Forum Moderators: phranque

Message Too Old, No Replies

Rewrite depending on variables

redirect where variable determines page

         

johnhh

6:01 pm on Dec 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



been bashing my head against a brick wall on this one!

The concept is that different pages get called depending on the variables.

so
/catalog/type/product.htm goes to /catalog/information.htm?type=type&product=product
whilst
/catalog/type.htm goes to catalog/prices.htm?type=type

#works but problem with 2 rules together

RewriteCond %{REQUEST_URI} ^/catalog/([^/]+)/([^/]+).htm
RewriteRule ^(.*) catalog/information.htm?type=%1&product=%2 [L,NS,QSA]

RewriteCond %{REQUEST_URI} ^/catalog/([^/]+).htm
RewriteRule ^(.*) catalog/prices.htm?type=%1 [L,NS,QSA]

However I have tried and cannot get this to work as there seems no way to detect that a / is missing in the second rule as it picks up the whole string and rewrites rule 1 as well!

If I take out either one of the rules the remaining rule works as intended.

Is this the correct technique? if so what expression will detect the non-existance of a /

Read most of the posts and guidelines here but I can't find anything that covers this.

jdMorgan

7:15 pm on Dec 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here are some modifications/simplifications that will prevent your second rule from always rewriting the output of the first rule, as well as eliminating unnecessary RewriteConds:

RewriteRule ^catalog/([^/]+)/([^/.]+)\.htm$ /catalog/information.htm?type=$1&product=$2 [QSA,L]
#
RewriteCond $1 !^prices$
RewriteRule ^catalog/([^/.]+)\.htm$ /catalog/prices.htm?type=%1 [QSA,L]

mod_rewrite in .htaccess is recursive; Your rules will be processed repeatedly until no more rewrites are invoked. This is independent of the presence or absence of the [L] flag -- Although you should still use that flag for efficiency.

Jim

johnhh

10:11 pm on Dec 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



thanks Jim - much appreciated

I'll try

RewriteCond $1!^prices$

I did try
! condition
but it was a lot longer and also failed to do the job!

John