Forum Moderators: phranque

Message Too Old, No Replies

modrewrite problem

problem encountered when page numbers encountered

         

opalplus

11:54 pm on Nov 1, 2006 (gmt 0)

10+ Year Member



Hi,

I'm using mod-rewrite on my dynamic category URLS which would make

eg. 'mysite.com/browse.php?id=358' to 'mysite.com/clean-title'

The code I am using for this is

Options +FollowSymLinks 
RewriteEngine on
RewriteRule ^clean-title?$ /browse.php?id=358 [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /browse\.php\?id=358\ HTTP/
RewriteRule ^browse\.php$ /clean-title? [R=301,L]

This works fine, however a few of my categories involve several pages... so in an attempt to make the urls look like

eg. 'mysite.com/browse.php?id=358&page=2' to 'mysite.com/clean-title-2'

i have used

RewriteRule ^clean-title-([^/]+)?$ /browse.php?id=358&page=$1 [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /browse\.php\?id=358&page=([^&]+)\ HTTP/
RewriteRule ^browse\.php$ /clean-title-%1? [R=301,L]

Now this works for the pages #2 and upward, however im getting a 404 error on the 1st page (mysite.com/clean-title) as the 1st page dosn't have "&page=1" on the end of the URL.

Anyone have any tips on how to make this work?

Cheers

jd01

12:25 am on Nov 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It looks like the second - (hyphen) is outside of the optional (followed by ?) back reference.

RewriteRule ^clean-title-([^/]+)?$ /browse.php?id=358&page=$1 [L]

Should be something more like:

RewriteRule ^clean-title(-([^/]+))?$ /browse.php?id=358&page=$2 [L]

Hope this helps.
Justin