Rewrite to SE friendly URL, causing infinite loop

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 3
Joined: 08 Apr 2013, 08:43

Rewrite to SE friendly URL, causing infinite loop

08 Apr 2013, 12:42

I'm trying to rewrite /page.asp?page_id=123 to /new-page.asp but I'm getting an infinite loop

RewriteCond %{QUERY_STRING} ^page_id=123$
RewriteRule ^/page\.asp$ /new-page.asp? [NC,R=301,L]

RewriteRule ^/new-page\.asp$ /page.asp?page_id=123 [NC,L]


I've read that adding the following before the above can prevent internal redirects, and prevent a loop
RewriteCond %{ENV:REDIRECT_STATUS} !200

Although it doesn't fix the issue, maybe it's only for Apache?

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: Rewrite to SE friendly URL, causing infinite loop

08 Apr 2013, 23:36

Hello,

The variables supported by ISAPI_Rewrite are described here - http://www.helicontech.com/isapi_rewrite/doc/RewriteCond.htm
The rules you're using are correct and shouldn't be looping. There's supposed to be something else. Lets see rewrite.log for a testing request. Logging issues are described in FAQ - http://www.helicontech.com/forum/10648-FAQ.html

Regards
Andrew

User avatar
Posts: 3
Joined: 08 Apr 2013, 08:43

Re: Rewrite to SE friendly URL, causing infinite loop

09 Apr 2013, 07:25

Hi Andrew,

Thanks for your reply, here are the relevant entries from the rewrite.log. It seems to be doing the initial redirect correctly and then the rewrite but then is matching again to do the redirect again.

Mon, 08-Apr-2013 11:28:43 GMT (3) applying pattern '^/page\.asp$' to uri '/page.asp'
Mon, 08-Apr-2013 11:28:43 GMT (4) RewriteCond: input='page_id=123' pattern='^page_id=123$' => matched
Mon, 08-Apr-2013 11:28:43 GMT (1) escaping /new-page.asp
Mon, 08-Apr-2013 11:28:43 GMT (2) explicitly forcing redirect with http://www.example.com/new-page.asp
Mon, 08-Apr-2013 11:28:43 GMT (2) internal redirect with /page.asp?page_id=123 [INTERNAL REDIRECT]
Mon, 08-Apr-2013 11:28:43 GMT (2) init rewrite engine with requested uri /new-page.asp
Mon, 08-Apr-2013 11:28:43 GMT (1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf

Mon, 08-Apr-2013 11:28:43 GMT (3) applying pattern '^/new-page\.asp$' to uri '/new-page.asp'
Mon, 08-Apr-2013 11:28:43 GMT (1) Rewrite URL to >> /page.asp?page_id=123
Mon, 08-Apr-2013 11:28:43 GMT (2) rewrite '/new-page.asp' -> '/page.asp?page_id=123'
Mon, 08-Apr-2013 11:28:43 GMT (2) internal redirect with /page.asp?page_id=123 [INTERNAL REDIRECT]
Mon, 08-Apr-2013 11:28:43 GMT (2) init rewrite engine with requested uri /page.asp?page_id=123
Mon, 08-Apr-2013 11:28:43 GMT (1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf

Mon, 08-Apr-2013 11:28:43 GMT (3) applying pattern '^/page\.asp$' to uri '/page.asp'
Mon, 08-Apr-2013 11:28:43 GMT (4) RewriteCond: input='page_id=123' pattern='^page_id=123$' => matched
Mon, 08-Apr-2013 11:28:43 GMT (1) escaping /new-page.asp
Mon, 08-Apr-2013 11:28:43 GMT (2) explicitly forcing redirect with http://www.example.com/new-page.asp
Mon, 08-Apr-2013 11:28:43 GMT (2) internal redirect with /page.asp?page_id=123 [INTERNAL REDIRECT]
Mon, 08-Apr-2013 11:28:56 GMT (2) init rewrite engine with requested uri /new-page.asp
Mon, 08-Apr-2013 11:28:56 GMT (1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf

If you need anymore information let me know.

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: Rewrite to SE friendly URL, causing infinite loop

09 Apr 2013, 17:16

That's strange. Redirect and rewrite shouldn't be looping.
One of the possibilities - double registration - http://www.helicontech.com/articles/isapi_rewrite-double-registration/
Second possibility that you need to use NS flag in both rules, however, it's unnecessary in cases like this.

Do you have any of other products installed on the server?

Regards
Andrew

User avatar
Posts: 3
Joined: 08 Apr 2013, 08:43

Re: Rewrite to SE friendly URL, causing infinite loop

10 Apr 2013, 07:13

Hi Andrew

I changed the IIS ISAPI filter setup from local registration to global registration and this has solved the problem. Maybe it was due to having the full trial version first and then switching to the Lite version, that caused the config issue?

Thanks again for your help.

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 18 guests