Page 1 of 1
Mod_rewrite rule...
Posted: Tue Nov 28, 2006 4:59 pm
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]
Posted: Tue Nov 28, 2006 5:11 pm
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]
Posted: Tue Nov 28, 2006 5:29 pm
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)
Posted: Tue Nov 28, 2006 7:02 pm
by redmonkey
mod_rewrite supports logging, turn it on and set an appropriate log level for debugging your rewrite rules.
Posted: Tue Nov 28, 2006 7:55 pm
by Buddha443556
Isn't %{QUERY_STRING} needed here somewhere?
Posted: Wed Nov 29, 2006 10:04 am
by Luke
I don't know. Anybody know a really good mod_rewrite tutorial/reference?
Posted: Wed Nov 29, 2006 7:31 pm
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
Posted: Wed Nov 29, 2006 7:39 pm
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.
