htaccess generic Rewrite Rule

Go To StackoverFlow.com

0

I have the following rewrite set up:

RewriteRule r/(.*) scripts/report.php?cp=1&id=$1  

It works great to redirect mydomain.com/r/123abc but it's redirecting all pages on the server that begin with an "r". Does anyone know how I can make this more specific to only redirect when the url is mydomain.com/r/ ? I should note that I need to keep this generic so I can't include mydomain.com in the rule.

2012-04-05 15:37
by cronoklee


0

Try putting a ^/ in front of your r/(.*) rewrite rule. This would make it:

RewriteRule ^/r/(.*) scripts/report.php?cp=1&id=$1
2012-04-05 15:43
by Jeff Geisperger
Ah perfect - thank - cronoklee 2012-04-05 15:55


0

I'm not sure if this works for you (not tested), but try it out:

# Rewrite ini
RewriteEngine on
RewriteBase /mydomain.com/

# Redirect all /mydomain.com/r/* calls to scripts/report.php
RewriteRule ^r/(.*)$ scripts/report.php?cp=1&id=$1 [QSA]

Hope that helps.

2012-04-05 15:42
by F. Müller


0

You should specify that the RegEx should match the entire string rather than just match the string. You can do this using the ^ and $ symbols:

RewriteRule ^r/(.*)$ scripts/report.php?cp=1&id=$1
2012-04-05 15:44
by Hubro
Ads