|
How to redirect from a canonical to a non-canonical web address |
|
|
|
Written by Dean Beedell
|
|
Wednesday, 23 November 2011 |
|
If you have a lot of domains all pointing to one central domain then you
might not want to have all those domains showing and instead you may
want them to resolve to just one domain.
What I mean by this is probably best described by an example, you have:
mycrapshop.com
mycrapshop.co.uk
shopsthatarecrap4you.co.uk
and you want each to point to:
my-shop-is-crap.com
So if I type "mycrapshop.co.uk" URL into Chrome's search bar then you
may want it to automatically show my-shop-is-crap.com. Why would you
want this? well, one reason is that in Joomla 1.0 & 1.5 site
cacheing can cause problems when you are displaying cached pages for one
domain when you are expecting another, both Joomla and the site visitor
can become quite confused when a domain name changes from page to page.
You may well be buying similar domains as "real estate" to prevent
others from stealing surrounding web estate or to cater for typing
errors in domain names, my-shop-is-carp.com would be a good example in
this case.
So, in host's your control panel you need to have one primary domain and
the other domains are 'parked' on top. Then you find the .htaccess file
in your root and you add the following redirect code after:
#
# mod_rewrite in use
RewriteEngine On
#
# rewrite my-shop-is-crap.com (always ensure that canonical www is diverted to non-canonical form)
#
RewriteCond %{HTTP_HOST} ^www.my-shop-is-crap.com [NC]
RewriteRule ^(.*)$ http://my-shop-is-crap.com/$1 [L,R=301]
#
# rewrite mycrapshop.com
#
RewriteCond %{HTTP_HOST} ^mycrapshop.com [NC]
RewriteRule ^(.*)$ http://my-shop-is-crap.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^www.mycrapshop.com [NC]
RewriteRule ^(.*)$ http://my-shop-is-crap.com/$1 [L,R=301]
#
# rewrite mycrapshop.co.uk
#
RewriteCond %{HTTP_HOST} ^mycrapshop.co.uk [NC]
RewriteRule ^(.*)$ http://my-shop-is-crap.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^mycrapshop.co.uk [NC]
RewriteRule ^(.*)$ http://my-shop-is-crap.com/$1 [L,R=301]
#
# rewrite shopsthatarecrap4you.co.uk
#
RewriteCond %{HTTP_HOST} ^shopsthatarecrap4you.co.uk [NC]
RewriteRule ^(.*)$ http://my-shop-is-crap.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^shopsthatarecrap4you.co.uk [NC]
RewriteRule ^(.*)$ http://my-shop-is-crap.com/$1 [L,R=301]
The above rewrites are directed to a non-canonical form of the target domain, ie. a URL without the "www"
This is deliberate, here is an example as to why you might want this -
if you have bought an SSL certificate without the www in the common name
then it is essential otherwise you will get an error when visitors
visit your shopping cart and try to checkout.
|
|
Last Updated ( Friday, 25 November 2011 )
|