301 Redirect problem

I want to redirect all requests beginning with www to the same pages without the www.

I’ve tried the 301 redirect code that cPanel creates, and code from another SitePoint member. Both have the same result: In one directory, most pages are not redirecting. Other directories, and top level pages are redirecting, and the redirects show as search engine-friendly.

Here’s the current .htaccess file:

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 /scripts/404.htm
ErrorDocument 500 /index.htm

My domain is on a hosted, shared Apache server running Linux. If you can think of any other details that might be helpful, please let me know. Thanks!

hm,

A new thread to continue? Oh, well …

You’re saying that the code is working in some directories but not others. Are these test URIs in the same domain? If the above code (the ErrorDocument lines have no impact on the mod_rewrite code) is in the DocumentRoot of the domain, it will redirect ALL requests to that domain. Therefore, I’ve got to ask about the domains you’re using and the physical paths (relative to each other) of your test URIs.

Regards,

DK

Thanks for following me to the new thread, DK. That was sweet of you. :slight_smile:

The domain for all the directories and pages is the same. The site is 15 years old, so we’ve gathered up quite a few links to www.example.com. However, we now use example.com as our canonical form.

Basically, since Google sees the www and non-www links as two separate pages, I’m afraid that we’re not getting the benefit of those many thousands of links in, and may even have been penalized. The 301 redirect seems to be the preferred method for dealing with this issue.

The content within the head of the webpages is the same for the pages that are redirecting properly, and the ones that aren’t. I’ve also now found some pages within the problematic directory that are redirecting properly, but there are very few of them. So this is problem is hard to pin down.

I’m going to send you a private message with some sample links, to see if you can figure out anything. If you don’t want to mess with it, just ignore the message. Thanks!

SOLVED, thanks to dklynn!

It turns out that a wayward tech support guy had added a second .htaccess file to my sub-directory that was having problems. I deleted the file, and all is well now.

Hope this helps someone else!

hm,

You’d better be a “hot babe” :girl: if you’re calling me “sweet!” :bouncy3:

Regards,

DK

Oops! Just saw this. Would “aging babe” be alright? :wink:

hm,

At my age, I can’t be choosey so, if the “hot” still applies, “aging babe” would be fine! :devil:

Regards,

DK

LOL! Now, now, Mr. Devil. :wink:

:blush:

Regards,

DK