Redirect http://www.your-domain.com to http://your-domain.com
By adding a few lines of code to the .htaccess file, you can redirect users.
First, why would you want to redirect a user from http://www.your-domain.com to http://your-domain.com, or vice versa? Here are two simple reasons:
- SSL is only for either www.your-domain.com or yourdomain.com - in the case that you purchase SSL for an online store or secure data transfer area of your website, you can be consistent.
- SEO efforts work better when you are consistent. By choosing www or no-www, you can focus your SEO strategy when linking to your site.
Here's the code:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\.your-domain\.com$ [NC]
RewriteRule ^(.*)$ http://your-domain.com/$1 [R=301,L]
The other way 'round
If you want to do the opposite, then use this:
# redirect if www.example.com (case-insensitive) to example.com
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule (.*) http://example.com/$1 [R=301,L]
Category: Knowledgebase
Created on: July 10th, 2008




