Mod_rewrite rule...

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

Mod_rewrite rule...

Post by Luke »

I need a regex book badly... but for now, can somebody help me out with this rule?

I'm trying to allow urls like /page/PAGECODE or /page/PAGECODE?querystringkey=querystringval&morekeys=morevalues

I thought this rule would work, but it doesn't seem to be grabbing the query string. :(

Code: Select all

RewriteCond %{REQUEST_URI} ^/page/(.*)?(.*) [NC]
RewriteRule (.*) /merchant2/merchant.mvc?Store_Code=BS&Screen=%1&%2 [L]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

? is a metacharacter that I recall in POSIX.

Untested:

Code: Select all

RewriteCond %{REQUEST_URI} ^/page/(.*)$ [NC]
RewriteRule ^/page/(.*)$ /merchant2/merchant.mvc?Store_Code=BS&Screen=$1 [L,QSA]
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

hmm... nope :(

Isn't that $ supposed to be a %

I tried switching it, but it still didn't work... gives me a 404 page (meaning it's not being rewritten correctly)
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post by redmonkey »

mod_rewrite supports logging, turn it on and set an appropriate log level for debugging your rewrite rules.
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

Isn't %{QUERY_STRING} needed here somewhere?
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

I don't know. Anybody know a really good mod_rewrite tutorial/reference?
User avatar
Fractal
Forum Commoner
Posts: 54
Joined: Tue Aug 16, 2005 1:28 pm

Post by Fractal »

I just use

RewriteEngine On
RewriteRule ^(file1|file2)(/.*)?$ $1.php$2

and update it statically. I used to have it look similar to yours until recently o_O
Last edited by Fractal on Sat Jan 20, 2007 5:43 am, edited 1 time in total.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

There are few useful tutorials posted in the 'Useful Resources' sticky in Apache, IIS and Servers. I think you are going to want to put some more in there though. This is one that I just got working a few days ago...

Code: Select all

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [S=1]
RewriteRule ^([A-Za-z0-9-_]+)/APPNAME-VISIT-ID-([A-Za-z0-9]+)/?$ /index.php?p=$1&sid=$2 [QSA,L]
RewriteRule ^([A-Za-z0-9-_]+)/?$ /index.php?p=$1 [QSA,L]
RewriteRule ^([A-za-z0-9-_]+)/activate_([0-9]+)/activate_with_([A-za-z0-9]+)/?$ /index.php?p=activate_user&user=$2&activation_code=$3 [QSA,L]
</IfModule>
I am almost certain this will not help you, but it might make you want to go out for pizza and beer. :wink:
Post Reply