RewriteCond back reference

Topics: User Forum
Jul 17, 2008 at 5:25 AM
Hi,

Just want to start out by saying this is a great tool and I've been able to do everything I needed until now.

I am trying to test if the %{HTTP_HOST} starts with a certain value and then substring a part of the value to use in a rewrite rule.

Here is the code:
RewriteCond %{HTTP_HOST} ^origin-(.*)$ [I]
RewriteRule  ^/(.*) %1/$1

And the log output:
Wed Jul 16 23:46:02 2008 - GetServerVariable_AutoFree - no joy (GetLastError()=1413)
Wed Jul 16 23:46:02 2008 - DoRewrites: New Url: '/xxxxen-US/'
Wed Jul 16 23:46:02 2008 - ApplyRules: depth=0
Wed Jul 16 23:46:02 2008 - ApplyRules: Rule 1 : 2 matches
Wed Jul 16 23:46:02 2008 - EvalCondition: ts1 'origin-localhost'
Wed Jul 16 23:46:02 2008 - ApplyCaseConversion: after  'origin-localhost'
Wed Jul 16 23:46:02 2008 - EvalCondition: checking 'origin-localhost' against pattern '^origin-(.*)'
Wed Jul 16 23:46:02 2008 - EvalCondition: match result: 2 (match)
Wed Jul 16 23:46:02 2008 - EvalConditionList: TRUE, Rule will apply
Wed Jul 16 23:46:02 2008 - ApplyCaseConversion: after  '%1/xxxxen-US/'
Wed Jul 16 23:46:02 2008 - ApplyRules: Result (length 14): %1/dxxxxen-US/
Wed Jul 16 23:46:02 2008 - ApplyRules: depth=1
Wed Jul 16 23:46:02 2008 - ApplyRules: Rule 1 : -1 (No match)
Wed Jul 16 23:46:02 2008 - ApplyRules: Rule 2 : -1 (No match)
Wed Jul 16 23:46:02 2008 - ApplyRules: Rule 3 : -1 (No match)
Wed Jul 16 23:46:02 2008 - ApplyRules: Rule 4 : -1 (No match)
Wed Jul 16 23:46:02 2008 - ApplyRules: Rule 5 : -1 (No match)
Wed Jul 16 23:46:02 2008 - ApplyRules: Rule 6 : -1 (No match)
Wed Jul 16 23:46:02 2008 - ApplyRules: Rule 7 : -1 (No match)
Wed Jul 16 23:46:02 2008 - ApplyRules: returning 0
Wed Jul 16 23:46:02 2008 - ApplyRules: returning 1
Wed Jul 16 23:46:02 2008 - DoRewrites: Rewrite Url to: '%1/xxxxen-US/'

The rules appear to be working but the %1 reference does not seem to resolve the (.*) from the RewriteCond.

Any insight would be appreciated.  Thanks in advance.
Coordinator
Jul 17, 2008 at 6:05 PM

I think this may be a bug.

Can you please insert this line into your ini file:

    CondSubstringBackrefFlag  %

and try again?

Jul 17, 2008 at 8:43 PM
Thanks for the quick response Cheeso.  It works like a charm now.