Jump to content

Recommended Posts

I am trying to do mod rewrite for my website to make the urls user and search engine firendly and am having trouble getting it to work.  This is what I've got and it doesn't work.
[code]RewriteEngine on
Options +FollowSymlinks
RewriteBase /
RewriteCond %{HTTP_USER_AGENT} ^EmailSiphon [OR]
RewriteCond %{HTTP_USER_AGENT} ^ExtractorPro
RewriteRule ^\.htaccess$ - [F]
RewriteRule ^(.*)/(.*)$ $1index?$2[/code]
here is the some of the links I would like to use

http://www.jackgodfrey.org.uk/index.php
http://www.jackgodfrey.org.uk/index.php?page=contact
http://www.jackgodfrey.org.uk/index.php?page=news&limit=1&pagenum=4

How would i include these links in the .htaccess file? ;D
Thanks...that works

Is there a way i can change the index to something else so it reads something/contact etc
Also who do I rewrite this url

http://www.jackgodfrey.org.uk/index.php?page=news&limit=1&pagenum=4

Many thanks for your help

I have found something strange and I don't think it's supposed to be happening.
If I click on the contact link multiple times even if I one from a different link i get this url

/index/index/index/contact and it doesn't display properly
Can you please tell me if I have got this right
[code]RewriteEngine on
Options +FollowSymlinks
RewriteBase /
RewriteCond %{HTTP_USER_AGENT} ^EmailSiphon [OR]
RewriteCond %{HTTP_USER_AGENT} ^ExtractorPro
RewriteRule ^\.htaccess$ - [F]

RewriteRule ^index/([A-Za-z_0-9]*) index.php?page=$1
[b]RewriteRule ^index/([A-Za-z_0-9]*)/([A-Za-z_0-9]*)/([A-Za-z_0-9]*) index.php?page=$1&limit=$2[/b]$pagenum=$3 [L][/code]
and how do i rewrite these urls for mod rewrite?  It for the last line of code where I would get [b]index.php?page=new&limit=1&pagenum=4[/b]

index.php?page=news&limit=$limit&pagenum=$prev_page
index.php?page=news&limit=$limit&pagenum=$a

This is in my pagination script I downloaded and the strings in there are set variables
That makes sense now but how do i change the actual urls in the page themselves?  I have it all working so the mod rewrite works but for the second rewrite rule.  I can't tell if it works becuase of the links on the page

<a href=index.php?page=news&limit=$limit&amp;pagenum=$prev_page>Prev.</a>

<a href=index.php?page=news&limit=$limit&amp;pagenum=$a> $a </a>

<a href=index.php?page=news&limit=$limit&amp;pagenum=$next_page><b>Next</b></a>

Here is my script so you can see how it works
[code]<?
//REMEMBER TO CONNECT TO DATABASE!

include_once("includes/connection.php");
    @mysql_connect($host, $user, $password) or die("ERROR--CAN'T CONNECT TO SERVER");
    @mysql_select_db($database) or die("ERROR--CAN'T CONNECT TO DB");
//**EDIT TO YOUR TABLE NAME, ECT.

$t = mysql_query("SELECT * FROM `news`");
  if(!$t) die(mysql_error());
   
$a                = mysql_fetch_object($t);
$total_items      = mysql_num_rows($t);
$limit            = $_GET['limit'];
$type             = $_GET['type'];
$page             = $_GET['pagenum'];

//set default if: $limit is empty, non numerical, less than 1, greater than 50
if((!$limit)  || (is_numeric($limit) == false) || ($limit < 2) || ($limit > 50)) {
     $limit = 1; //default
}
//set default if: $page is empty, non numerical, less than zero, greater than total available
if((!$page) || (is_numeric($page) == false) || ($page < 0) || ($page > $total_items)) {
      $page = 1; //default
}

//calcuate total pages
$total_pages     = ceil($total_items / $limit);
$set_limit          = $page * $limit - ($limit);

//query: **EDIT TO YOUR TABLE NAME, ECT.

$q = mysql_query("SELECT id,title,content, DATE_FORMAT(time, '%W %D %M %Y') as date, photo FROM news ORDER BY time DESC LIMIT $set_limit, $limit");
  if(!$q) die(mysql_error());
     $err = mysql_num_rows($q);
       if($err == 0) die("No matches met your criteria.");
$numofrows = mysql_num_rows($q);
//Results per page: **EDIT LINK PATH**
echo("   
<a href=?page=news&limit=10&amp;pagenum=1></a>
<a href=?page=news&limit=25&amp;pagenum=1></a>
<a href=?page=news&limit=50&amp;pagenum=1></a>");

//show data matching query:
while($code = mysql_fetch_array($q)) {

    echo "<div id=\"right\"><h3>".$code['title']."</h3><i>Date added: ".$code['date']."</i><p class=\"style3\"><img src=images/".$code['photo']." align=\"right\" class=\"right\">".nl2br($code['content'])."</p></div>\n";
}

$id = urlencode($id); //makes browser friendly

//prev. page: **EDIT LINK PATH**

$prev_page = $page - 1;

if($prev_page >= 1) {
  echo("<b>&lt;&lt;</b> <a href=?page=news&limit=$limit&amp;pagenum=$prev_page><b>Prev.</b></a>");
}

//Display middle pages: **EDIT LINK PATH**

for($a = 1; $a <= $total_pages; $a++)
{
   if($a == $page) {
      echo("<b> $a</b> | "); //no link
     } else {
  echo("  <a href=?page=news&limit=$limit&amp;pagenum=$a> $a </a> | ");
     }
}

//next page: **EDIT THIS LINK PATH**

$next_page = $page + 1;
if($next_page <= $total_pages) {
   echo("<a href=?page=news&limit=$limit&amp;pagenum=$next_page><b>Next</b></a> &gt; &gt;");
}

//all done
?>[/code]

Here is my updated .htaccess mod rewrite
[code]Options +FollowSymLinks
RewriteEngine on
RewriteBase /

RewriteRule ^honeylands/(.*) index.php?page=$1 [NC]
RewriteRule ^honeylands/(.*)/(.*)/(.*) index.php?page=$1&limit=$2&pagenum=$3 [L][/code]

Is this right for the internal urls? It seems to display correctly in the browser address bar but it defualts back to the home page which is now /honeylands/index

<a href=/honeylands/news/$limit/$prev_page><b>Prev.</a>
<a href=/honeylands/news/$limit/$next_page><b>Next</a>
<a href=/honeylands/news/$limit/$a> $a </a>
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.