What's wrong with my mod_rewrite? [solved]

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

What's wrong with my mod_rewrite? [solved]

Post 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]
Last edited by Luke on Mon Oct 30, 2006 5:10 pm, edited 1 time in total.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Seems to be working with apache 2.2.3 on winxp.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post 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?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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 ;)
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post 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.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

It wasn't my rules... it was the server. Thanks anyways guys!
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post 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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post 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
Post Reply