isapi_rewrite to Ape, infinite loop.

Helicon Ape provides support for Apache .htacces and .htpasswd configuration files for Microsoft IIS.
User avatar
Posts: 22
Joined: 19 Aug 2012, 20:24

isapi_rewrite to Ape, infinite loop.

19 Aug 2012, 20:34

Hello,

I am upgrading from isapi_rewrite 3 to Ape, and have an infinite loop on rules that previously worked.
This is to make a friendly url rewrite to an asp page, and also redirect the asp to the friendly url (if someone typed it in / linked it manually)

Code: Select all
RewriteRule ^/test/rewrite$ /test/rewrite.asp [NC,L,U]
RewriteRule ^/test/rewrite\.asp$ /test/rewrite [NC,R=301]

This worked with isapi_rewrite3, but does an infinite redirect loop with Ape.
The log files show that the first rule matches, but then the /test/rewrite.asp is getting sent through the rules again, from the top, as if it's a new request. This then matches the second rule, which does the infinite loop.

Side notes:
The order of the two rules doesn't matter (I reversed them in case it was a problem with the L not stopping).
Also, the docs are unclear about whether R=301 also needs an L. In isapi_rewrite3 an L was not needed; the R stops further rules. I tested with and without an L, with no difference.

Thank you,
Bob

User avatar
Posts: 871
Joined: 12 Mar 2012, 09:54

Re: isapi_rewrite to Ape, infinite loop.

20 Aug 2012, 05:31

Hello, Bob

Please try to add the NS flag after rewrite rule to avoid loops:

RewriteRule ^/test/rewrite$ /test/rewrite.asp [NC,L,U,NS]
RewriteRule ^/test/rewrite\.asp$ /test/rewrite [NC,R=301]

User avatar
Posts: 22
Joined: 19 Aug 2012, 20:24

Re: isapi_rewrite to Ape, infinite loop.

20 Aug 2012, 12:34

Hi,

This worked on the second rule, thank you.

Code: Select all
RewriteRule ^/test/rewrite$ /test/rewrite.asp [NC,L,U]
RewriteRule ^/test/rewrite\.asp$ /test/rewrite [NC,NS,R=301]


I see many posts about this; it's an old issue with Apache, just new for me going to Ape. I suppose it's no harm on the other rules, since they would never match anyway. Perhaps I'll just do NS,L and NS,R on all rules.

There are a couple approaches using environmental variables to catch it early in one rule, and exit. I would always want to REALLY stop on an L or R rule, and never go through again.

This question uses %{IS_SUBREQ}
http://stackoverflow.com/questions/9555 ... -is-useful

This post mentions %{REDIRECT_STATUS}
http://www.webmasterworld.com/apache/4299003.htm

Are either of these available? An early global rule would be a nice way to stop on an internal redirect.

Thanks,
Bob

User avatar
Posts: 871
Joined: 12 Mar 2012, 09:54

Re: isapi_rewrite to Ape, infinite loop.

21 Aug 2012, 07:33

Hello,

This rule should work in Ape as well:

RewriteCond %{IS_SUBREQ} (?:t|1|true) [NC]
RewriteRule .? - [L]

Please try and report the result.

User avatar
Posts: 22
Joined: 19 Aug 2012, 20:24

Re: isapi_rewrite to Ape, infinite loop.

23 Aug 2012, 19:27

This worked like a charm, intercepting all internal redirects and exiting.

Thanks,
Bob
(I could swear I posted this reply already.)

Return to Helicon Ape

Who is online

Users browsing this forum: No registered users and 27 guests