Force www With htaccess

For SEO it is important to use a set standard of how you present your domain. The most popular approach is to use the sub-domain www. Many people don't know this but is the same as, you will be sent to the same page but they will have different URLs. For SEO if a search engine saw it will crawl this page, check the content and index the content. Then later if it goes and crawls the search engines will see the same content but on different URLs and think it is duplicate content and therefore will penalise this domain in the search engine ranking.

Consistent URLs

The best way to get around this problem is to make sure that all your URLs on your site use a consistent URL format either or It makes no difference which format you choose, the search engine just worries about duplicate content. ## Use www

I prefer to make sure all my domains use www sub-domain, this is the format most people are used to seeing on search engines and web sites. If people are used to seeing it then they will not worry about the URL. Now that you have chosen your preferred format and changed all your links to your site to use this format then you are done, right, wrong! If you stick just with this you run the risk of someone linking to you but forgetting to put a www on the front, the search engines will then crawl through this link and see duplicate content and penalise your domain. To combat this problem you have a couple of options the best solution is to perform a check of the URL on each page if it doesn't contain the www then perform a 301 redirect to your domain with the www sub-domain. The best way of using this solution is to use htaccess, this will run before any pages are loaded and allows you to change the URL with a 301 redirect. ## .htaccess To Redirect URLs

To use htaccess to redirect URL just copy and paste the snippet below and replace with your domain.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$$1 [L,R=301,NC]

Add www With HTTP/HTTPS

RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]


Reliable uptime monitoring and instant alerts for any website downtime.

Get 50% off forever using the code 50OFFUP.