Forum Moderators: phranque

Message Too Old, No Replies

RewriteCond backreferences to RewriteRule not working

Backreferences to a RewriteRule from a RewriteCond statement aren't working

         

iamthefred

5:25 pm on Aug 20, 2005 (gmt 0)



I am having trouble with this mod_rewrite htaccess. It is for a comic site that occasionally uploads strip images before putting them on the main page. The RewriteCond statement checks if the current date is before the date of the image requested, and if it is the user is redirected to a "Not Found" page. However, the backreferences to the RewriteRule do not seem to work:

RewriteEngine On
RewriteCond %{TIME_YEAR}%{TIME_MON}%{TIME_DAY} <$3$2$1
RewriteRule ^([0-9]{2})\-([0-9]{2})\-([0-9]{4})\.(gif¦jpg¦jpeg)$ http://example.com/notfound.htm [R,L]

When I substitute a numerical date for the backreferences, it works fine:

RewriteCond %{TIME_YEAR}%{TIME_MON}%{TIME_DAY} <20050820

Can anyone tell me why these backreferences aren't working?

jdMorgan

7:01 pm on Aug 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



iamthefred,

Welcome to WebmasterWorld!

Yes, because backreferences can only be used in the left side of a RewriteCond -- See the mod_rewrite documentation. There is no variable-to-variable compare in mod_rewrite. A point solution exists (for certain servers only) using POSIX 1003.2 regex atomic back-references and the principal of equivalence (if A+B = A+A, then A=B), but your best bet is to use PERL or PHP to accomplish your goal.

Jim