Forum Moderators: open

Message Too Old, No Replies

301 Redirect - Is this acceptable?

         

wrkalot

5:27 pm on Jan 8, 2007 (gmt 0)

10+ Year Member



I asked my host to do a 301 permanent redirect for me. What they did was add a file called httpd.ini in my root with the following code:

[ISAPI_Rewrite]

RewriteCond Host: mydomain\.com
RewriteRule /(.*) [mydomain.com...] [RP,L]

I am having canonical URL issues with Google so I want non-www urls to be 301ed to WWW urls like this:

mydomain.com/page1.htm

I would like that redirected to

www.mydomain.com/page1.htm

Will this rewrite rule do this properly? Is it seen as a 301 basically?

pageoneresults

5:45 pm on Jan 8, 2007 (gmt 0)

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



Your code...

RewriteCond Host: mydomain\.com 
RewriteRule /(.*) http://www.mydomain.com/$1 [RP,L]

What I have as a working example...

RewriteCond Host: ^example\.com 
RewriteRule (.*) http\://www\.example\.com$1 [I,RP]

There appear to be some slight differences between theirs and what I've been using for years. I can't specify whether or not theirs is correct or incorrect. I do know that the code I provided is doing exactly what you specify.

jdMorgan

6:15 pm on Jan 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Theoretically, there should be no need to escape the periods in the substitution URL, since it is not a regular expression, and therefore the string portion can be taken as a literal. IOW, it would make no sense to redirect to www<any single character>example<any single character>com.

In Apache mod_rewrite, the only characters than need be escaped in the substitution URL are the "back-reference and variable indicators" - "%" and "$". If the same is true for ISAPI Rewrite, then the two code snippets are essentially identical except for the handling of the leading slash, which is equivalent.

Jim

[edit] Speling [/edit]

[edited by: jdMorgan at 6:24 pm (utc) on Jan. 8, 2007]

wrkalot

6:22 pm on Jan 8, 2007 (gmt 0)

10+ Year Member



Thanks for the quick replies!

SeoCatfish

12:07 am on Jan 20, 2007 (gmt 0)

10+ Year Member



but what do you do to get www.domain.com/index.asp to 301 to www.domain.com without causing an infinite loop?