Remove Trailing Dot in Domain Name

Yesterday, I read an article talking about fully qualified domain names and its possible issues. Each domain name in fact has a dot at the end. The internet browser can either load rendykstan.github.com or rendykstan.github.com.. As you can see rendykstan.github.com. loads a 404.

The workaround introduced by the article requires you to have some knowledge in configuring Apache and enabling mod_rewrite.

1
2
3
4
5
ravi@taraka:~$ sudo a2enmod rewrite
Enabling module rewrite.
Run '/etc/init.d/apache2 restart' to activate new configuration!
ravi@taraka:~$ sudo service apache2 restart
 * Restarting web server apache2                                                                                                                                         ... waiting .                                                                                                                                                   [ OK ]

If you are like me, uses a vhost. You will need to go to the sites-available directory to locate your vhost file and add the block of code below under your vhost. Change google to your domain.

/etc/apache2/sites-available/vhost
1
2
3
4
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^google\.com$
RewriteRule ^(.*)$ http://google.com$1 [L,R=301]

A quick check to see if it is working using *curl.

1
2
3
4
5
6
7
8
9
10
11
ravi@taraka:~$ curl -I http://google.com.
HTTP/1.1 301 Moved Permanently
Location: http://www.google.com/
Content-Type: text/html; charset=UTF-8
Date: Tue, 19 Mar 2013 16:43:45 GMT
Expires: Thu, 18 Apr 2013 16:43:45 GMT
Cache-Control: public, max-age=2592000
Server: gws
Content-Length: 219
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN