Canonical 301 redirect doesn't work on 20% of pgs

I used cPanel to set up a 301 redirect www.my domain.com in to mydomain.com equivalents. We have a number of incoming links with both formats, and want the search engines to understand that they all go to the same place.

For about 60% of the pages, the redirect works just fine. However, about 20% of the pages still show a simple 200 / direct link response.

The 301 was put into place this past Thursday, and the site is based in the US, so the DNS should have fully propagated by now.

Also, the redirect checkers seems to disagree. A couple say that more than one canonical form of our links shows up as a 200 response. Others say the 301 is working as it should. ?

Here’s the code cPanel put into our .htaccess file:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.mydomain\.com$
RewriteRule ^(.*)$ “http\:\/\/mydomain\.com\/$1” [R=301,L]

I’m baffled. Any insights are appreciated. Thanks!

hm,

Use:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\\.mydomain\\.com$
RewriteRule .? http://mydomain.com%{REQUEST_URI} [R=301,L]

You do not escape characters in the redirection. We just had another member who’d stated that someone had told him to do so but that’s quite incorrect. Also the quotes in the redirection are wrong. Have a look at Tim Berners-Lee’s Uniform Resource Identifiers (URI): Generic Syntax. Just remember that escaping characters is only done for the regular expression engine which looks for that to be done in regular expressions - the redirection is NOT a regular expression.

Regards,

DK

Thanks so much for your reply, and for the code! I’ll give it a try now.

I didn’t write the original code. cPanel did. That means that many others will face the same problem. Do you know offhand if there’s a way to alert the cPanel developers to these errors?

Most cPanel users, myself included, are not versed in programming. (Although I do know some grep, and wondered about the things you mentioned. Good to know I had a least a little bit of a clue! :wink:

Update:

The new redirect code that you provided is working for the index page and for all directories EXCEPT the one that contains most of our content. There’s been enough time now that the DNS should have propagated.

The directory’s format is mydomain.com/topics/topicpage.htm

Any ideas as to the problem? Thanks in advance!

hm,

The code above only changes (removes) the www. Therefore, if there is a problem, it’s in whatever code you’re hiding from us (to keep us from helping?). Please show your .htaccess (removing your domain name and using example.com, if you please).

When you do that, please provide a test URI (no domain) so I can see where it’s being hijacked.

Regards,

DK

David: This is my entire .htaccess file. Note that it now includes the code you provided:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule .? http://example.com%{REQUEST_URI} [R=301,L]

ErrorDocument 400 /index.htm
ErrorDocument 401 /index.htm
ErrorDocument 403 /index.htm
ErrorDocument 404 /index.htm
ErrorDocument 500 /index.htm

On a side note, should I change the “index.htm” to http://example.com/ ? I just found out last night that Google penalizes for pointing to the index page rather than the root domain for one’s homepage.

Again, thanks in advance for your help. It was certainly not my intention to hide anything. I want to provide whatever is necessary for those more knowledgeable than myself to help me.

David, I’m going to start a new thread. My site has been without a proper redirect for several days, and I need more input. However, I’m very grateful for the help you’ve given me. Thanks for your time and expertise!

hm,

The ErrorDocument merely requires an absolute redirection … which you are doing. Note that absolute redirections can be internal (as you’ve done) or external (http://yadda.yadda.com/index.htm).

Regards,

DK