Forum Moderators: phranque
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]
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
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.aspGET /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]
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]
Jim
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.
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
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!