Forum Moderators: phranque

Message Too Old, No Replies

Redirect Fix in htaccess

Will htaccess fix this?

         

grandma genie

8:32 pm on Nov 22, 2010 (gmt 0)

10+ Year Member



I inadvertently (stupidly) have created links from one part of my site to another without making sure the link used the correct URL that included the www. My site has two sections. One is all html and the other is osCommerce. When i created a URL link to the osCommerce section, I forgot to make sure the link shows the www and so it is going to the osCommerce portion as domain.com/osc instead of www.domain.com/osc. Can I fix this in htaccess or do I have to go and fix all those links to include the www? Here is my current htaccess redirect instructions:

# Externally redirect certain non-canonical hostnames to canonical hostname, preserving http/https protocol
# FQDN-format www.domainA.com or with appended port number
RewriteCond %{HTTP_HOST} ^www\.domainA\.com(\.|\.?:[0-9]+)$ [NC,OR]
# www- or non-www domainB.com
RewriteCond %{HTTP_HOST} ^(www\.)?domainB\.com [NC]
RewriteCond %{SERVER_PORT}s ^(443(s)|[0-9]+s)$
RewriteRule ^(.*)$ http%2://www.domainA.com/$1 [R=301,L]

Domain B is a different name entirely, so it would just concern Domain A, one with www and one without. Should I add this:

# www- or non-www domainA.com
RewriteCond %{HTTP_HOST} ^(www\.)?domainA\.com [NC,OR]

- Jeannie

wilderness

9:14 pm on Nov 22, 2010 (gmt 0)

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



Your going to be required to fix them eventually!
Why not just bite the billet and make the corrections.

There are a multitude of html editor tools that were designed specifically for these types of corrections.

One I've used for a long while is "Search and Replace 98".
Once you become accustomed to the editor, hundreds of references may be corrected in seconds.
Then you just upload the new files and delete the backups (which the software renames).

jdMorgan

7:50 pm on Nov 30, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The correct change to the code would be:

# Externally redirect certain non-canonical hostnames to canonical hostname, preserving http/https protocol
# FQDN-format www.domainA.com or with appended port number
RewriteCond %{HTTP_HOST} ^www\.domainA\.com(\.|\.?:[0-9]+)$ [NC,OR]
# Non-www domainA
RewriteCond %{HTTP_HOST} ^domainA\.com [NC,OR]
# www- or non-www domainB.com
RewriteCond %{HTTP_HOST} ^(www\.)?domainB\.com [NC]
RewriteCond %{SERVER_PORT}s ^(443(s)|[0-9]+s)$
RewriteRule ^(.*)$ http%2://www.domainA.com/$1 [R=301,L]

However, you should not put this code in place until after you have corrected all of the links on your site. Google especially will 'complain' if you link to URLs which redirect, a sign that they consider such an error to be a sign of low site quality -- and that's not a sign you want to give!

Jim

grandma genie

5:12 am on Dec 1, 2010 (gmt 0)

10+ Year Member



I have gotten almost all the links fixed. I have one more directory to do and then all the links will be correct. I asked my hosting company to change the domain name to the correct one for both sections of the site, so now the osCommerce section has the correct www name. Therefore, the only places that will show the old non-canonical names will be the ones that are in search engine listings from the past. I will keep an eye on the error log for anything that comes up. And check Google Analytics, too. Hopefully this will resolve a lot of problems. Thanks, Jim.

jdMorgan

9:11 pm on Dec 6, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It would be a Good Thing(TM) to always include the canonicalization code on *any* server. Among other things, this prevents search engines from *ever* listing a non-canonical protocol, hostname, or port number, even if you make a linking error...

Jim