RewriteCond Backreference is null when I use an intermediate RewriteRule

Topics: User Forum
Jan 9, 2013 at 4:24 PM

Hi All,

I'm using the backreference feature to reuse the first capture group from a RewriteCond line in a RedirectRule, as follows:

=====

RewriteCond %{HTTP_HOST} ((www\.)?website\.com) [I]

RedirectRule ^.*$        http://www.website2.com/folder/page.htm?redirectFrom=*1  [I,R=301]

=====

This works fine.  However, I want to exclude robots.txt from the redirect so I inserted a rule between the RewriteCond and RedirectRule, ending up with the INI file as follows:

=====

RewriteCond %{HTTP_HOST} ((www\.)?website\.com) [I]

RewriteRule ^/robots\.txt$ /disallow-all-robots.txt [I,L]

RedirectRule ^.*$        http://www.website2.com/folder/page.htm?redirectFrom=*1  [I,R=301]

=====

With this configuration, the backreference in the RedirectRule (*1) always returns null.  Can anyone explain why this is happening?  I've read the documentation about the order of processing of rules in the IIRF.INI file and wonder if it is something to do with that, but I just don't fully understand the documentation on that point :(

Thanks in advance!

Steven