Remove WWW from your Domain Name / Website URL

What does the WWW mean nowadays? It is just the world wide web, synonym for the internet, right?

Then, why should we prefix our websites with www always? It has been a practice for so long to have website domain names start with www. Why don’t we just get rid of it, and have clear and neat simple domains?

Hey, check out http://www.va, the website of Vatican City. .va is the TLD (top level domain) assigned to Vatican City. Does the domain name wwww.va seem to miss the domain name, like www.something.va? 🙂 Nope. Here www is the domain label, and the regular www subdomain is not used. Clear?

For example, in case of www.teck.in, technically the www is nothing but a subdomain, just like sree in sree.teck.in.

Now, how to remove the www even if a user types it in the address bar of the browser?

[advt]

.htaccess Rewrite

Add the following to your .htaccess file of your Apache web server, which will rewrite the URL removing www part.

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

PHP / WordPress

If you do not have access to htaccess file, copy the PHP code to top of your wp-config.php file, and replace yourdomain.com with your domain name.

If you do not have access to wp-config.php, you can add these lines on the very top of your header.php in your current theme, within the php tags. Make sure you do not put any extra space in there, which would break your RSS feed otherwise!

If you are using any other PHP CMS, you can still use this code. Just make sure that, this gets executed before any other processing.

if ( strpos($_SERVER['HTTP_HOST'], 'www.') === 0 ) {
header('HTTP/1.1 301 Moved Permanently');
header('Location: http://yourdomain.com' . $_SERVER['REQUEST_URI']);
exit();
}

For this blog teck.in, I use the php code. If you type the address as https://teck.in/, it will be converted into https://teck.in automatically.

Also, if you are an Search Engine Optimization guy, don’t forget to set the preferred domain for search in the Webmaster Central as the one without the www part.

Why don’t you get rid of www and join the no-www club?

Be the first to comment

Leave a Reply