How to force www. through .htaccess
- Blog
- How to force www. through .htaccess
Forcing www. is just one of many functions you can perform via an .htaccess file. For more information on .htaccess, visit our blog post:
If you want to force www. add the following code to your .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^vasdomen.com
RewriteRule (.*) http://www.vasdomen.com/$1 [R=301,L]
If you want to force https add the following code to your .htaccess file:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
For more information on the benefits of switching from HTTP to HTTPS, see the following article:
More about the transition from HTTP to HTTPS:
In case you want to force www. and https protocol Your code should look like this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^vasdomen.com
RewriteRule (.*) http://www.vasdomen.com/$1 [R=301,L]
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]