Chinese University and Importance of non-www Redirection

Do you have a website? If yes, say it’s called domain.com. Does it serve the right page if you entered a www and non-www versions of it? On some occasions we see sites that are displayed only when we enter one type of URL. Otherwise, it doesn’t load up when we enter another variation of the URL.

Chinese University

Chinese University

For illustration purposes, let’s have a look at the website of Chinese University of Hong Kong. It has an internet address of www.cuhk.edu.hk so when you enter this URL you will find the site gets redirected to www.cuhk.edu.hk/v6/en/ (a topic that’s warrants another blog post) which is fine. But the issue I want to point out is that when you enter cuhk.edu.hk the server can’t quite figure out displaying the same page and instead, issues the error page.

Chinese University

Chinese University

Which isn’t correct, right?

Sometimes people are lazy to type the three w’s so when they link to sites they omit the “www” part. So if they are linking to sites similar to the Chinese University of Hong Kong, they link to cuhk.edu.hk instead of www.cuhk.edu.hk. They are obviously pointing to dead links even if 9 out of 10 times they assume such type of (non-www) links work by simply redirecting the non-www URL to the www version.

Therefore, for sites that have this issue, it’s basically missing out on opportunity for traffic. At the same time search engines count this discrepancy and ignore inbound links that point to broken non-www links.

To check if your site has this issue, you can use the non-www checker tool. For Chinese University, which doesn’t display its homepage with a non-www URL, the shows “The remote name could not be resolved: ‘cuhk.edu.hk'”.

To fix this issue we consider 301 redirection on two server platforms: Apache and Windows.

Apache
1. Check to make sure that Apache Rewrite Mode is activated.
2. Download the .htaccess file at your website’s root folder so you can edit it. It would be great if you can make a backup copy to ensure you can restore the site when things go wrong.
3. Add the following code in the .htaccess file (replace the domain.com with your domain).

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

4. Upload the .htaccess file and check in your browser if your site loads to the www version when you enter the non-www URL. If the redirection works, then we have successfully fixed the issue.

Windows
1. Use the Internet Services Manager to create a new IP-based website using the http://example.com URL or alternatively you can avoid using a unique IP by using the host header (virtual website) of www.example.com.

2. Check if both non-www version (http://example.com) and www version (http://www.example.com) are pages that exist (status 200 OK) by using a Server Header Check tool.

3. Add your domain-revised version of the following code to the default home page for http://example.com:

< %@ Language=VBScript %>
<% Response.Status="301 Moved Permanently" Response.AddHeader "Location", http://www.example.com %>

4. Once the default page is online, check your site using the non-www version (ie http://example.com) to ensure the redirect is working.