Posts Tagged ‘mod_rewrite’

How to remove www from domain

remove-wwwMore than a few people have asked for an easy way to make sure their visitors always see http://yourdomain.com instead of http://www.yourdomain.com so we figured it’s about time for a post on how to automatically remove the www from your domain (or vice versa). First, edit (or create) your .htaccess file, using mod_rewrite to either remove the www from, or add it to your domain. To remove the www from your domain: RewriteEngine On RewriteCond %{HTTP_HOST} www.example\.com RewriteRule (.*) http://example.com/$1 [R=301,L] To add the www to your domain: RewriteEngine On RewriteCond %{HTTP_HOST} example\.com RewriteRule (.*) http://www.example.com/$1 [R=301,L] Next, simply upload your .htaccess file to the root directory of your web server and you should be all set. Be sure to give it a quick test and make sure everything works properly.