Organizational Research By

Surprising Reserch Topic

How do I use .htaccess to always redirect from HTTP to HTTPS?



asked May 20, 2015 in htaccess by rahulgii
0 votes
38 views



Related Hot Questions

4 Answers

0 votes

I wouldn't use mod_rewrite, you can achieve it simply with mod_alias:

Redirect permanent / https://other-site

Where 'other-site' is the hostname you want to redirect to, ommitting the www. prefix that you do not want.

answered May 20, 2015 by rahulgii
0 votes

There are so many solutions:

RewriteEngine On
RewriteCond %{HTTPS} !^on$
RewriteRule (.*) https://yourdomain/$1 [R,L]
answered May 20, 2015 by rahulgii
0 votes

two solutions . add either of them to your .htaccess

RewriteEngine on
RewriteCondition %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L] 

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
answered May 20, 2015 by rahulgii
0 votes

If you're using a load balancer you'll need to use a different conditional. This works for AWS ELB:


    RewriteEngine On
    RewriteCond %{HTTP:X-Forwarded-Proto} !https
    RewriteRule (.*) https://yourdomain.com/$1 [R=301,L]
answered May 20, 2015 by rahulgii

...