Redirect example.com to www.example.com
• Apr 3rd, 2008 • Category: Tips and TricksWith regards to Search Engine Optimization, you want to get full tracking on your websites and give search engines a clear insight into your website.
If your website is www.example.com, then ensure you only allow visitors to access the site through example.com or www.example.com. Only one of these should be allowed, to ensure your site is viewed as one.
The quickest way of doing this is making a .htaccess file in the root of your site. To redirect all example.com visits to www.example.com, insert the following code in your file.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^yoursite\.com$ [NC]
RewriteRule ^(.*)$ http://www.yoursite.com/$1 [L,R=301]
That’s it! Make sure you change yoursite to your domain and .com to your top level domain. Make sure the file is called “.htaccess” with nothing in front of the full stop.