When you attach multiple domain names to a site, search engines can become confused and your rankings may suffer. If they find the same page at two or more different URLs, the search engines will sometimes filter out the extra listings, but there’s no guarantee of which ones they filter. You also don’t want people linking to your site with non-standard domain names because that will tend to divide your inbound link strength. The best practice is to standardize hostnames and URLs so that each page has one unique URL.
Valid reasons for having more than one domain name attached to the same website include helping visitors who may type a domain name with spelling mistakes, hyphens, no hyphens or confuse different names, as well as preventing competitors and typosquatters from using a similar domain name. For a few dollars per year per domain name, it often makes sense to buy all the obvious mistakes and permutations of a primary domain. Additionally, businesses sometimes change names, necessitating a change of hostname. It is then helpful to the user to cause the former domain name to redirect to the new, standard domain name.
Google recommends using 301 redirects to standardize URLs. A few lines of code can ensure that alternative URLs consistently lead to your preferred URL, maximizing the potential for search engine appearances. Best practice is to set up permanent 301 redirects for any extra domains, as well as the www subdomain or the non-www domain.
To find the right code, start by identifying what type of server you have. If you don’t know, use https://urivalet.com/ to inspect your server headers and identify your server type. Common server types include Apache, nginx, and Windows IIS.
Apache & NGINX Servers – Best Solution
If you have an Apache or nginx web server that supports mod_rewrite, add the following code to a .htaccess file in the top level directory. When using this code, be sure to replace the test.com domain name with your domain name. If your site uses ‘https’ you will need to change ^80$ to ^443$, since https usually runs on port 443.
The www version:
Alternative versions that are sometimes useful, depending on server and security certificate configurations:
Microsoft IIS Servers – Best Solution
If you are using a Microsoft IIS web server, use ISAPI_rewrite to simulate Apache’s .htaccess feature. To begin, you or your hosting provider needs to install ISAPI_rewrite on the server. Then you would create a httpd.ini file in the top level directory as follows, replacing the test domain name with yours:
ASP Classic – Alternative Solution for IIS
If you have an IIS server and cannot install ISAPI_rewrite, but have ASP classic scripting available, the following code will fix most URL canonicalization issues. Place the code at the top of each page before thetag, and be sure to replace test.com with your domain name.
PHP – Alternative Solution for Apache, NGINX, IIS
If your server does not support .htaccess, nor ISAPI_rewrite, but does have PHP, the following code may be used. Place the code at the top of each page before thetag, and be sure to replace test.com with your domain name.
IIS Alternative Solution
If you have an IIS server, but don’t have ISAPI_rewrite, ASP Classic, nor ASP scripting, Ian McAnerin has published a very helpful article that explains how the server administrator can set up permanent 301 redirects on IIS .
These solutions assume you prefer to use the www subdomain for your web site. If you would rather have a non-www URL, simply remove each instance of “www\.” and “www.” from the rewrite conditions and rules. As with all code, please test thoroughly before deploying to your live server. Your website may require different code than the examples presented here.
Have questions or want more information? Please contact us today.