Friday, July 1, 2016

Redirect non-www to www in .htaccess


Many customers at some point request to force either the www or non-www version of their site to display in their visitor's browser. For example always have www.example.com or simply example.com display in their visitor's web browser. There is a common thought that forcing one format is better for search engine optimization. This article will guide you through how to perform this action in your .htaccess in the cPanel for your primary domain.

RewriteEngine On

RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

No comments:

Post a Comment