Page 1 of 1

What's wrong with my mod_rewrite? [solved]

Posted: Mon Oct 30, 2006 4:23 pm
by Luke
This is causing a "500 Internal Server Error"... anybody know why?

Code: Select all

Options +FollowSymlinks
RewriteEngine On
# 
RewriteCond %{REQUEST_URI} ^/p/(.*)/(.*)	[NC] 
RewriteRule (.*) /merchant2/merchant.mvc?Screen=PROD&Product_Code=%1&Store_Code=BS [L]
RewriteCond %{REQUEST_URI} ^/pc/(.*)/(.*)/(.*)	[NC]
RewriteRule (.*) /merchant2/merchant.mvc?Screen=PROD&Product_Code=%1&Category_Code=%2&Store_Code=BS [L]
RewriteCond %{REQUEST_URI} ^/c/(.*)/(.*)	[NC] 
RewriteRule (.*) /merchant2/merchant.mvc?Screen=CTGY&Category_Code=%1&Store_Code=BS [L]

Posted: Mon Oct 30, 2006 4:31 pm
by volka
Seems to be working with apache 2.2.3 on winxp.

Posted: Mon Oct 30, 2006 4:34 pm
by Luke
ok how about this...
this file is in C:\wamp\www\mod_rewrite

Code: Select all

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/s/(.*)/(.*)	[NC] 
RewriteRule (.*) index.php?Screen=CTGY&Store_Code=BS&Category_Code=%1 [L]
I type in... http://localhost/mod_rewrite/s/varfoo/varbar and I get a 404 not found... am I doing something wrong?

Posted: Mon Oct 30, 2006 4:46 pm
by volka
Doesn't {REQUEST_URI} always contain the whole uri (without protocol and server), i.e. /mod_rewrite/s/varfoo/varbar in this case?
I'm too lazy to test this right now ;)

Posted: Mon Oct 30, 2006 4:52 pm
by Luke
:oops: I don't know... it's confusing as hell though... I've never really built any mod_rewrite rules before. It makes almost no sense to me.

Posted: Mon Oct 30, 2006 5:10 pm
by Luke
It wasn't my rules... it was the server. Thanks anyways guys!

Posted: Wed Nov 01, 2006 10:50 am
by Luke
Another quick question... Here is one of my rules...

Code: Select all

RewriteCond %{REQUEST_URI} ^/pc/(.*)/(.*)/(.*) [NC]
RewriteRule (.*) /merchant2/merchant.mvc?Screen=PROD&Store_Code=BS&Category_Code=%1&Product_Code=%2&open_tab=%3 [L]

RewriteCond %{REQUEST_URI} ^/pc/(.*)/(.*)/$ [NC]
RewriteRule (.*) /merchant2/merchant.mvc?Screen=PROD&Store_Code=BS&Category_Code=%1&Product_Code=%2&open_tab=description [L]
What I want is for the third variable is automatically set to "description" if it isn't specified... what I've done above isn't working properly... what am I doing wrong? I really need to work on my regex skills.

Posted: Wed Nov 01, 2006 11:24 am
by John Cartwright
I think you'll have to use another rule

Code: Select all

RewriteCond %{REQUEST_URI} ^/pc/(.*)/(.*)/ [NC]
RewriteRule (.*) /merchant2/merchant.mvc?Screen=PROD&Store_Code=BS&Category_Code=%1&Product_Code=%2&open_tab=description [L]
Above the rest of them

Posted: Wed Nov 01, 2006 11:31 am
by Luke
This worked...

Code: Select all

RewriteCond %{REQUEST_URI} ^/pc/(.*)/(.*)/(.*)/ [NC]
RewriteRule (.*) /merchant2/merchant.mvc?Screen=PROD&Store_Code=BS&Category_Code=%1&Product_Code=%2&open_tab=%3 [L]

RewriteCond %{REQUEST_URI} ^/pc/(.*)/(.*) [NC]
RewriteRule (.*) /merchant2/merchant.mvc?Screen=PROD&Store_Code=BS&Category_Code=%1&Product_Code=%2&open_tab=description [L]
I just have to add the extra slash at the end if I want to designate the open_tab... which is fine! :D :D