Forum Moderators: phranque

Message Too Old, No Replies

rewrite problem

not redirecting

         

WhosAWhata

8:23 pm on Aug 2, 2005 (gmt 0)

10+ Year Member




RewriteEngine On
RewriteCond %{REQUEST_URI} ^browse/cat$
RewriteRule (.*) index.php?browse=cat
RewriteCond %{REQUEST_URI ^browse/cat/(se¦mi¦pa¦re¦sp¦st)$
RewriteRule browse/cat/(.*) index.php?browse=$1
RewriteCond %{REQUEST_URI ^browse/volume$
RewriteRule (.*) index.php=browse=vol
RewriteCond %{REQUEST_URI ^browse/volume/[0-9]$
RewriteRule browse/volume/(.*) index.php?browse=sub&vol=$1
RewriteCond %{REQUEST_URI ^browse/year$
RewriteRule (.*) index.php?browse=year
RewriteCond %{REQUEST_URI ^browse/year/20[0-9][0-9]$
RewriteRule browse/year/(.*) index.php?browse=sub&year=$1
RewriteCond %{REQUEST_URI ^browse/title)$
RewriteRule (.*) index.php?browse=title
RewriteCond %{REQUEST_URI ^browse/title/reverse$
RewriteRule (.*) index.php?browse=reverse

browse/cat should go to index.php?browse=cat
browse/cat/se should go to index.php?browse=se
browse/volume should go to index.php?browse=vol
browse/volume/3 should go to index.php?browse=sub&vol=3

etc...

all return a 404 error

jd01

12:13 am on Aug 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi WhosAWhata,

browse/cat

The conditions are actually unnecessary for this type of rewrite. This should work fine for the page above, and you can adapt the others to follow suit:

RewriteEngine ON
RewriteRule ^browse/cat$ /index.php?browse=cat [L]
RewriteRule ^browse/cat/(.*) /index.php?browse=$1 [L]

and a more efficient version:

RewriteEngine ON
RewriteRule !^browse/cat [S=2]
RewriteRule ^[^/]+/.{3}$ /index.php?browse=cat [L]
RewriteRule ^[^/]+/[^/]+/(.*) /index.php?browse=$1 [L]

In this set we only match the entire pattern of browse/cat once, then we use a catch-all ([^/]+ = anything that is not a /) so we are only comparing one character against the pattern. The use of a forward looking negative pattern is much more efficient than a generic catch-all EG .*

!^browse/cat - [S=2] Says if the URL does not start with browse/cat skip the next two rules.

Hope this helps.

Justin

WhosAWhata

2:42 am on Aug 3, 2005 (gmt 0)

10+ Year Member



i ended up using this before your reply

RewriteEngine On
RewriteRule browse/(cat/圭at)$ index.php?browse=cat
RewriteRule browse/cat/(se妃i如a字e存p存t)$ browse/cat/$1/
RewriteRule browse/cat/(se妃i如a字e存p存t)/$ index.php?browse=$1
RewriteRule browse/(volume宅olume/)$ index.php?browse=vol
RewriteRule browse/volume/0([0-9])$ index.php?browse=sub&vol=0$1
RewriteRule browse/volume/0([0-9])/$ index.php?browse=sub&vol=0$1
RewriteRule browse/(year尖ear/)$ index.php?browse=year
RewriteRule browse/year/20([0-9][0-9])$ browse/year/20$1/
RewriteRule browse/year/20([0-9][0-9])/$ index.php?browse=sub&year=20$1
RewriteRule browse/(title宇itle/)$ index.php?browse=title
RewriteRule browse/title/(reverse字everse/)$ index.php?browse=reverse

it works, but if there are any improvements I'd be glad to take them

jd01

7:48 pm on Aug 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



First, you need a [L] flag, unless you *know* you do not.

If the rules are in the .htaccess, the right side should have a preceding / so, the rewrite to index.php should be /index.php

EG RewriteRule browse/volume/?$ /index.php?browse=vol [L]

If the rules are in the httpd file, the left side of the rule should have the preceding /.

EG RewriteRule /browse/volume/?$ index.php?browse=vol [L]

These duplicate matches can all be shortened and combined using an?(optional) quantifier:

RewriteRule browse/(volume宅olume/)$ index.php?browse=vol
RewriteRule browse/volume/0([0-9])$ index.php?browse=sub&vol=0$1
RewriteRule browse/volume/0([0-9])/$ index.php?browse=sub&vol=0$1

to (assuming .htaccess)
RewriteRule browse/volume/?$ /index.php?browse=vol [L]

and
RewriteRule browse/volume/0([0-9])/?$ /index.php?browse=sub&vol=0$1 [L]

You might also consider using a version of the skip I pointed out earlier, that would allow you to match the pattern browse/ only once, instead of having to match up to 10 times for the last rules to finally qualify.

RewriteRule!^browse [S=NUMBEROFRULESYOUHAVE]
RewriteRule [^/]+/volume/?$ /index.php?browse=vol [L]
RewriteRule [^/]+/volume/0([0-9])/?$ /index.php?browse=sub&vol=0$1 [L]

Justin

Added: You could do some more combining above...