Forum Moderators: phranque

Message Too Old, No Replies

301 Redirect Infinite Loop

ISAPI Rewrite 3, 301 Redirect Infinite loop

         

eyeyen

10:32 pm on Aug 15, 2008 (gmt 0)

10+ Year Member



Hi All,
I am getting an infinite loop doing a 1 to 1 redirect of a page. This also happens for some other pages as well. I need help, I've been Googling and trying different things, but with no success.

For example, this is the link (generic):
http://www.example.com/corporatelogos.asp

and I am trying to 301 redirect it to:
http://www.example.com/company-gifts/

Here is my .htaccess file (it's actually bigger than this, here's a snippet):

RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /corporatelogos\.asp\ HTTP/
RewriteRule ^corporatelogos\.asp?$ http://www.example.com/company-gifts/ [R=301,L]
RewriteRule ^company-gifts(/)?$ corporatelogos.asp [L]

And checking the response headers, when I enter http://www.example.com/corporatelogos.asp I get this:
Keep-Alive: 300
Connection: keep-alive
Cookie: visitorid=27642637491226; ASPSESSIONIDSQDSDRBQ=FOMEGONBCNCFBFNDNGJNJDNG

HTTP/1.x 301 Moved Permanently
Server: Microsoft-IIS/5.0
Date: Fri, 15 Aug 2008 17:14:08 GMT
X-Powered-By: ASP.NET
Location: http://www.example.com/company-gifts/
Content-Length: 251
Content-Type: text/html
----------------------------------------------------------
http://www.example.com/company-gifts/

GET /company-gifts/ HTTP/1.1
Host: www.example.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Cookie: visitorid=27642637491226; ASPSESSIONIDSQDSDRBQ=FOMEGONBCNCFBFNDNGJNJDNG

HTTP/1.x 301 Moved Permanently
Server: Microsoft-IIS/5.0
Date: Fri, 15 Aug 2008 17:14:08 GMT
X-Powered-By: ASP.NET
Location: http://www.example.com/company-gifts/
Content-Length: 251
Content-Type: text/html
----------------------------------------------------------
http://www.example.com/company-gifts/

GET /company-gifts/ HTTP/1.1
Host: www.example.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Cookie: visitorid=27642637491226; ASPSESSIONIDSQDSDRBQ=FOMEGONBCNCFBFNDNGJNJDNG

HTTP/1.x 301 Moved Permanently
Server: Microsoft-IIS/5.0
Date: Fri, 15 Aug 2008 17:14:08 GMT
X-Powered-By: ASP.NET
Location: http://www.example.com/company-gifts/
Content-Length: 251
Content-Type: text/html

And it continues to loop and 301 to http://www.example.com/company-gifts/ .

Here is my Rewrite.log file:

[rid#12937944/initial] (1) Htaccess process request D:\Inetpub\WWWroot\domain_Helicon\ISAPI_Rewrite3\httpd.conf
[rid#12937944/initial] (1) Htaccess process request d:\inetpub\wwwroot\domain\.htaccess
[rid#12937944/initial] (3) applying pattern '^(.*)$' to uri 'corporatelogos.asp'
[rid#12937944/initial] (4) RewriteCond: input='www.example.com' pattern='^domain\.com$' => not-matched
[rid#12937944/initial] (3) applying pattern '^company-gifts(/)?$' to uri 'corporatelogos.asp'
...
[rid#12937944/initial] (3) applying pattern '^welcome.asp?$' to uri 'corporatelogos.asp'
[rid#12937944/initial] (3) applying pattern '^corporatelogos\.asp?$' to uri 'corporatelogos.asp'
[rid#12937944/initial] (4) RewriteCond: input='GET /corporatelogos.asp HTTP/1.1' pattern='^[A-Z]{3,9}\x20/corporatelogos\.asp\x20HTTP/' => matched
[rid#12937944/initial] (1) escaping http://www.example.com/company-gifts/
[rid#12937944/initial] (2) explicitly forcing redirect with http://www.example.com/company-gifts/
[rid#12937944/initial] (2) internal redirect with /corporatelogos.asp [INTERNAL REDIRECT]
[rid#12937944/initial] (2) init rewrite engine with requested uri /company-gifts/
[rid#12937944/initial] (1) Htaccess process request D:\Inetpub\WWWroot\domain_Helicon\ISAPI_Rewrite3\httpd.conf
[rid#12937944/initial] (1) Htaccess process request d:\inetpub\wwwroot\domain\.htaccess
[rid#12937944/initial] (3) applying pattern '^(.*)$' to uri 'company-gifts/'
[rid#12937944/initial] (4) RewriteCond: input='www.example.com' pattern='^domain\.com$' => not-matched
[rid#12937944/initial] (3) applying pattern '^company-gifts(/)?$' to uri 'company-gifts/'
[rid#12937944/initial] (1) escaping /corporatelogos.asp
[rid#12937944/initial] (1) Rewrite URL to >> /corporatelogos.asp
[rid#12937944/initial] (2) rewrite 'company-gifts/' -> '/corporatelogos.asp'
[rid#12937944/initial] (2) internal redirect with /corporatelogos.asp [INTERNAL REDIRECT]
[rid#12937944/initial] (2) init rewrite engine with requested uri /corporatelogos.asp
[rid#12937944/initial] (1) Htaccess process request D:\Inetpub\WWWroot\domain_Helicon\ISAPI_Rewrite3\httpd.conf
[rid#12937944/initial] (1) Htaccess process request d:\inetpub\wwwroot\domain\.htaccess
[rid#12937944/initial] (3) applying pattern '^(.*)$' to uri 'corporatelogos.asp'
[rid#12937944/initial] (4) RewriteCond: input='www.example.com' pattern='^domain\.com$' => not-matched
[rid#12937944/initial] (3) applying pattern '^company-gifts(/)?$' to uri 'corporatelogos.asp'
...
[rid#12937944/initial] (3) applying pattern '^welcome.asp?$' to uri 'corporatelogos.asp'
[rid#12937944/initial] (3) applying pattern '^corporatelogos\.asp?$' to uri 'corporatelogos.asp'
[rid#12937944/initial] (4) RewriteCond: input='GET /corporatelogos.asp HTTP/1.1' pattern='^[A-Z]{3,9}\x20/corporatelogos\.asp\x20HTTP/' => matched
[rid#12937944/initial] (1) escaping http://www.example.com/company-gifts/
[rid#12937944/initial] (2) explicitly forcing redirect with http://www.example.com/company-gifts/
[rid#12937944/initial] (2) internal redirect with /corporatelogos.asp [INTERNAL REDIRECT]

I've gone line-by-line and see that it's indeed looping, but how do I stop it? I thought a RewriteCond would stop it?

Other 301 redirects work fine, but this one doesn't seem to work. Any ideas? Advice appreciated in advance!

[edited by: jdMorgan at 12:13 am (utc) on Aug. 19, 2008]
[edit reason] example.com and shortened. [/edit]

g1smd

9:51 am on Aug 16, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You have a redirect and a rewrite.

One of them should test THE_REQUEST and the other should test REQUEST_URI in the preceding RewriteCond to avoid this.

I forget which should go with which, but there are plenty of prior examples here in the forum.

jdMorgan

1:56 pm on Aug 16, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This code would be correct and work properly on Apache, but there are differences between Apache mod_rewrite and IIS ISAPI_Rewrite. It appears that either the [L] flags don't work as documented in ISAPI Rewrite, or that THE_REQUEST is 'updated' by internal rewrites (which should not be the case, since it is supposed to be the HTTP request header as sent by the client).

Also, please try the "Live HTTP Headers" add-on for Firefox/Mozilla browsers; It is more reliable than on-line headers checkers at showing *all* HTTP transactions, and may reveal additional information about the client-server interaction.

That's really all I can offer, as my experience with ISAPI_Rewrite is very limited.

Jim

eyeyen

5:16 pm on Aug 18, 2008 (gmt 0)

10+ Year Member



Thank you all for the replies.

jdMorgan, I installed that plug in and this is what I have. The interesting thing to note is that on the test server, this 301 redirect works fine. I commented out the 301 rewriterule and it when accessing the new url, it works fine, which leads me to believe it's either the server, or ISAPI_Rewrite handles the [L] flag differently than Apache (like you said), because this should be working fine, right?

Here are the headers:

==================LIVE SITE==================

http://www.example.com/corporatelogos.asp

GET /corporatelogos.asp HTTP/1.1
Host: www.example.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Cookie: visitorid=27642637491226; ASPSESSIONIDSQDSDRBQ=FOMEGONBCNCFBFNDNGJNJDNG

HTTP/1.x 301 Moved Permanently
Server: Microsoft-IIS/5.0
Date: Mon, 18 Aug 2008 16:59:15 GMT
X-Powered-By: ASP.NET
Location: http://www.example.com/company-gifts/
Content-Length: 251
Content-Type: text/html
----------------------------------------------------------
http://www.example.com/company-gifts/

GET /company-gifts/ HTTP/1.1
Host: www.example.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Cookie: visitorid=27642637491226; ASPSESSIONIDSQDSDRBQ=FOMEGONBCNCFBFNDNGJNJDNG

HTTP/1.x 301 Moved Permanently
Server: Microsoft-IIS/5.0
Date: Mon, 18 Aug 2008 16:59:15 GMT
X-Powered-By: ASP.NET
Location: http://www.example.com/company-gifts/
Content-Length: 251
Content-Type: text/html
----------------------------------------------------------
http://www.example.com/company-gifts/

GET /company-gifts/ HTTP/1.1
Host: www.example.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Cookie: visitorid=27642637491226; ASPSESSIONIDSQDSDRBQ=FOMEGONBCNCFBFNDNGJNJDNG

HTTP/1.x 301 Moved Permanently
Server: Microsoft-IIS/5.0
Date: Mon, 18 Aug 2008 16:59:15 GMT
X-Powered-By: ASP.NET
Location: http://www.example.com/company-gifts/
Content-Length: 251
Content-Type: text/html
----------------------------------------------------------

I can post the rewrite.log file again, but it's exhibiting the same behavior (looping, the uri seems to stay at the old and new urls, and doesn't change to say, another resource like a .gif or the css). Thoughts? Thanks for replying.

[edited by: jdMorgan at 12:02 am (utc) on Aug. 19, 2008]
[edit reason] example.com and shortened. [/edit]

jdMorgan

12:09 am on Aug 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's evident that you have additional code on your server which is not on your test machine, since there is nothing in this code that would redirect /company-gifts/ to itself.

You might try modifying the rule to get rid of the trailing slash, since removing an unnecessary trailing slash is a common thing to do, and may be the purpose of the additional code.


RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /corporatelogos\.asp\ HTTP/
RewriteRule ^corporatelogos\.asp$ http://www.example.com/company-gifts [R=301,L]
RewriteRule ^company-gifts$ /corporatelogos.asp [L]

Just to be clear, a URL with a trailing slash is a request for a directory index (a directory listing of that directory), whereas a URL without a trailing slash is a request for a "page" or an included object. Therefore, you should not be adding a slash to this URL, and the additional code on the server may be intended to remove it, thus creating a tertiary loop.

Jim

eyeyen

4:16 pm on Aug 19, 2008 (gmt 0)

10+ Year Member



Hi Jim,
I tried that and its still looping. I understand what you mean by the tertiary loop, but something is still causing it to loop.

The thing is this is just one page, and I was hoping to solve this so I can apply it to product pages (which are exhibiting the same looping).

Maybe it has something to do with ISAPI_Rewrite3, because I've spoken with some colleagues of mine and they agree that these rules should work flawlessly. It's just weird how it works on the test server, but not the live site...

Any thoughts? Thanks for your time, you've been helpful thus far.

jdMorgan

4:54 pm on Aug 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You're going to have to thoroughly investigate all of the config files and all of the .htaccess files in the filepath to which this URL resolves, and look at the CMS and scripts that are involved in this request. Any of these can generate a redirect response.

By "tertiary" I meant a "three-step" loop, since it looks likely that there are more than just your two rules involved in this looping; The fact remains that neither of your rules will redirect /company-gifts/ to itself, so there must be a "third player" in this game... and you need to find it.

Jim

eyeyen

8:15 pm on Aug 20, 2008 (gmt 0)

10+ Year Member



Just to update, figured it out, it was some IIS settings of ISAPI_Rewrite. Just needed to do this (for anybody else having this problem):

Go to IIS - Web Sites - Web Site Properties - ISAPI filters and make sure there no ISAPI_Rewrite3 filter there.
ISAPI_Rewrite3 filter should be in IIS - Web Sites - Web Sites Properties - ISAPI filters.

Cheers, thanks a lot Jim!