Redirect http to https and www

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]

  • 4 Users Found This Useful

Was this answer helpful?

Related Articles

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...

Can I change my username?

Usernames are setup in the manner for security. Most programs will allow you to save the...

Cross Origin Request Error

When receiving a cross-origin / cross original request, CORS header 'Access-Control-Allow-Origin'...

How can I redirect http to https?

Create an .htaccess file with the following contents and upload it to your public_html directory....

What is a Top-Level-Domain (TLD)?

TLD stands for Top Level Domain. This includes any domain names which suffix is .com, .net, .org,...