Redirect website to https:// and www. via .htaccess

To forward a website to use both www. and https:// use the following in an .htaccess file:

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]


If that code doesn't work please try the following...

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

  • 104 Users Found This Useful

Was this answer helpful?

Related Articles

Can you write a script for me?

We do not write scripts but will be more than happy to guide you in the right direction. Most the...

My site was hacked

This typically occurs when you are running a script/app on your website which is out-dated and...

403 Error on POST

This can occur for several reasons: Be sure your file permissions are correct. If the file needs...

Inode issues

There are many issues that can arise from reaching your inode limit. The inode limit is the total...

Why does it show the Ultra Web Hosting home page when I go to my site?

There are several reasons for this. Ensure you do not have https at the beginning of your...