Ajax software
Free javascripts
↑
Main Page
The solution we’re proposing is to do 301 redirects to a single “standard” version of the link. Lucky you,
the functionality is already there! The
fix_category_product_url()
function from
url_redirect
.inc.php
already takes care to redirect any errant or outdated link to its “proper” version, in case the
URL isn’t already what it should be.
Trying to load any of the two previously mentioned links would simply redirect you to:
http://seophp.example.com/Products/SEO-Toolbox-C6/Link-Juice-P31.html
Dealing with Multiple Domain Names Properly
Though it’s less popular these days, some people desire to have multiple domain names pointing to the
same site. For example, say you have three domain names:
www.example.com
www.example.org
www.example.net
The problem is that, especially if you market all three domains, people are free to link to any of these
domains. That’s a major duplicate content issue. You must pick a “standard” domain and permanently
redirect the other domains to that domain.
Let’s pick
www.example.com
. This is how to do it with mod_rewrite:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
Done! Now everything will get redirected to
www.example.com
. Let’s analyze the rules in detail.
This is the first time you’re using
RewriteCond
. You use
RewriteCond
to place a condition for the
rule that follows. In this case, you’re interested in verifying that the site has been accessed through
www.example.com
. Take another look at the
RewriteCond
line:
RewriteCond %{HTTP_HOST} !^www\.example\.com
This line specifies a condition that is true when the host name (
HTTP_HOST
) is not (
!
)
www.example
.com
. The rewrite rule captures the entire query string of the original URL, as
(.*)
, and passes it to
http://www.example.com
, doing a 301 redirect to the new location. This way, for example, a query
to
http://www.example.org?query=string
would be 301 redirected to
http://www.example
.com?query=string
.
Using Redirects to Change Domain Names
Sometimes you
have
to change your domain name. Usually this happens in M&A (mergers and acquisi-
tions) cases. Although undesirable, there is a right way to do this, and many wrong ones. Typically both
domains need to point to the same web site now that the merger occurred. The
worst
thing you can do is
simply point both domains to the same content via DNS. This will result in search engines not knowing
90
Chapter 4: Content Relocation and HTTP Status Codes
c04.qxd:c04 10:40 90
Ajax software
Free javascripts
→ R7