querystring recursion due to filename extension

Jul 12, 2009 at 9:13 PM


The following rule is causing IIRF to recurse:

RewriteRule  ^/(.*).myext  /$1.asp?%{QUERY_STRING}    [U]

where test case is:


The .myext in the querystring is throwing off IIRF.  What can I do to mitigate this?

Thanks in advance!


Jul 13, 2009 at 2:44 AM
Edited Jul 13, 2009 at 7:44 AM

You need to tighten your regex. 

The first (.*) in your regex is wrong - it is much to liberal as gobbles up everything in the URL, including the query string, if the query string ends in .myext. I think what you want is to match .myext to the script name, in which case, there must not be a ? before .myext. So, construct the regex to say "any sequence of characters not including a question mark".

  RewriteRule ^/([^\?]+)\.myext    /$1.asp?%{QUERY_STRING}  [U]

The regex ([^\?]+) means: any sequence of one or more chars from the given range. And the given range is [^\?], in other words, anything that is not a question mark

You could also do it with lazy quantifiers, in other words, a regex that says "match the very first .myext".  This one looks like this:

  RewriteRule ^/(.+?)\.myext    /$1.asp?%{QUERY_STRING}  [U]

This one says match the minimum number of any character followed by .myext.  But don't use this.   It would work for the simple example, where .myext occurs twice.  But it would not work for the general case, like one where your script has no extension, while .myext is still present in the query string.   

Jul 13, 2009 at 4:13 AM

Thanks Cheeso.

This is exactly what I was looking for.

Separately, the URL-encoded special characters in my query string are not being rendered precisely.  Is this IIRF related?  A discussion list search yielded a similar topic but I didn't glean a solution.

For example, ?redirecturl=http%3A%2F%2Fwww.mydomain.com%2Fsub%2Fhome.myext

becomes redirecturl=httpAFFwww.mydomain.comFsubFhome.myext

Is there a flag or change I need to put in my .ini file?



Jul 13, 2009 at 5:59 AM
Edited Jul 13, 2009 at 5:59 AM

yes!  There's a flag for that.  Insert this line in the INI file:

  CondSubstringBackrefFlag    *

 (near the top, before any rules)

Jul 13, 2009 at 7:01 AM

Worked perfectly.

The new version is sweet.