Remove “www.” from your URLs
If you have .htaccess and mod_rewrite enabled on your server, you can force the www. out of your URLs with a little rewrite trick. I’ve seen this used on a few servers, notably Slashdot. Try accessing the aforementioned site and see what happens. Notice the www. disappears. I like this trick because I’ve always found the www. to be a little redundant. Doesn’t the http:// in the address designate to the server that a web page should be requested? What has been the point of the www. then? It’s time we move on and get rid of this antiquated part of the URL that is so common on the Internet.
With that in mind, I give you my code that will clean up your URL a little bit (paste this into your .htaccess file):
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]
Note that [R=301] redirects the request to the new URL and returns a 301 permanently moved reponse.
This trick will validate your site with no-www.org as a Class B domain.
If you use this update for a Movable Type blog, make sure you change the URL information in your Weblog Config and in mt.cfg. If you don’t, comment submission won’t work and your server will have to do a lot of unnecessary redirecting.
1 comment
(4 years, 5 months ago)
Brilliant! Very clearly outlined. Could you perhaps make a note that those users using a forum such as Invision Board should change their settings before editing the .htaccess file - otherwise they can’t login!