In Mary Jo's blog Redirecting Multiple Domains to One, she shows us how to redirect multiple domains into one.
It's common these days to have multiple domain pointers to a website. I might for instance have cfwebstore.com, cfwebstore.net, dogpatchsoftware.com, etc. all pointing to my site. Things become a bit problematic when using ecommerce software and you need to use SSL to check out. CFWebstore has a variety of security measures that rely on the SSL having the same domain name as the primary site. So what we need to do is redirect the user to the same domain regardless of what domain alias they may have entered the site on.
Now, it's fairly easy to just detect these and redirect the user back to the main home page on your primary domain. But what if you have users coming into various sub-pages on the site and want to just transparently rewrite the URL? Well, this is easily done using existing variables in CFWebstore. The file you will want to add your code to is fbx_Settings.cfm. Go to around line 293, just before the clearsession section, and add something like this (add a cfcase for each domain you wish to redirect):
<cfset TheDomain=LCase(CGI.HTTP_HOST)>
<cfswitch expression="#TheDomain#">
<cfcase value="www.dogpatchsw.com">
<cflocation addtoken="No" url="http://www.cfwebstore.com/#Request.currentURL#">
</cfcase>
</cfswitch>
Even if you only have one domain, search engines will index pages in your website as both with the WWW and without. This will look like duplicate content and may actually lower you page rank. We can use the code above to redirect domain name to the subdomain WWW.
<cfset TheDomain=LCase(CGI.HTTP_HOST)>
<cfswitch expression="#TheDomain#">
<cfcase value="cfwebstore.com">
<cflocation addtoken="No" url="http://www.cfwebstore.com/#Request.currentURL#">
</cfcase>
</cfswitch>
Recently, it was pointed out by Johnny Nguyen at www.drsandassociates.com, that the above code produces a 302 temporary redirect instead of a 301 permanant redirect. We need the permanant redirect to tell the search engines to stop indexing the non-WWW pages. We can achieve the 301 redirect by using <cfheader> instead of <cflocation>.
<cfset TheDomain=LCase(CGI.HTTP_HOST)>
<cfswitch expression="#TheDomain#">
<cfcase value="cfwebstore.com">
<CFHEADER statuscode="301" statustext="Moved Permanently">
<CFHEADER name="Location" value="http://www.cfwebstore.com/#Request.currentURL#">
</cfcase>
</cfswitch>
You can verify the type of redirect by going to http://www.webtoolhub.com/tn561352-url-redirection-checker.aspx
If you use Google Webmaster Tools, you can actually tell Google to display your pages with or without the 'www'. I'm sure the other search engines are starting to correct this problem.