Simple mod rewrite

New to mod_rewrite? This is a good place to start.

Simple mod rewrite

Postby atDev » Tue Jul 28, 2009 1:00 pm

Can anyone assist me on getting this to work?
RewriteRule ^affiliate\/idevaffiliate\.php\?id=([0-9]+)$ /order/aff\.php?aff=$1 [R=301,L]
atDev
 
Posts: 2
Joined: Tue Jul 28, 2009 12:59 pm

Postby richardk » Tue Jul 28, 2009 3:28 pm

Query strings are matched with the %{QUERY_STRING} variable and RewriteConds.

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} ^(.*&)?id=([0-9]+)(&.*)?$ [NC]
RewriteRule ^affiliate/idevaffiliate\.php$ /order/aff.php?aff=%2 [NC,R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby atDev » Tue Jul 28, 2009 3:58 pm

That didn't seem to work. But based on your suggestion I used this and it seems to work ok.

Do you see any problems in using this?

Code: Select all
RewriteCond %{QUERY_STRING} ^id=([0-9]+)$ [NC]
RewriteRule ^affiliate/idevaffiliate\.php$ /order/aff.php?id=%1 [NC,R=301,L]
atDev
 
Posts: 2
Joined: Tue Jul 28, 2009 12:59 pm

Postby richardk » Tue Jul 28, 2009 5:34 pm

That didn't seem to work.

SCRIPT_FILENAME should have been QUERY_STRING
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{QUERY_STRING} ^(.*&)?id=([0-9]+)(&.*)?$ [NC]
RewriteRule ^affiliate/idevaffiliate\.php$ /order/aff.php?aff=%2 [NC,R=301,L]


Do you see any problems in using this?

It won't match if there are other query string variables (including just an extra &).
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 22 guests

cron