Reputation: 8594
I am trying to redirect:
http://website.com & http://website.com/index.php to https://website.com
All the solutions I found will redirect http://website.com/test.php (that has login) to a 401 page. I just want / and /index.php to redirect to HTTPS
The following code does not work for my needs:
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
and
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
Upvotes: 1
Views: 32
Reputation: 785058
You may use this rule as your topmost rule:
RewriteEngine On
RewriteCond %{HTTPS} !on [OR]
RewriteCond %{REQUEST_URI} ^/index\.php$ [NC]
RewriteRule ^(?:index\.php)?$ https://%{HTTP_HOST} [L,NE,R=301]
Make sure this is top rule and you test it from a new browser.
Upvotes: 1