Link to home
Start Free TrialLog in
Avatar of mikely
mikely

asked on

mod-rewrite - Can I use a RewriteCond backreference in the PATTERN for the subsequent RewriteRule

While this works as I'd expect (rewrites http://www.whatever.com/BLAH to http://www.whatever.com/test.php):

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/BLAH/ [NC]
RewriteRule ^BLAH/$ test.php [NC,L]

, I was half expecting this to work (both http://www.whatever.com/BLAH and http://www.whatever.com/SCHMLAH being rewritten to http://www.whatever.com/test.php):

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/(BLAH|SCHMLAH)/ [NC]
RewriteRule ^%1/$ test.php [NC,L]

I have tested that the backreference from the RewriteCond contains a value by tracing it in the substitution of the RewriteRule. It seems that i cannot use a backreference from a RewriteCond in the PATTERN of the RewriteRule.

Is this the case or am I doing something wrong?

Cheers
ASKER CERTIFIED SOLUTION
Avatar of sleep_furiously
sleep_furiously

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I just found a real nice mod_rewrite cheat sheet that is real helpful when you are writing rules and conditions.  You can download it from http://www.ilovejackdaniels.com/apache/mod_rewrite-cheat-sheet/

I hope that Cheat Sheet can help you as much as it has helped me out.