Skip to main content

Apache http to https redirection [Resolved]

I'm using below .htaccess rule to redirect all http requests to https.

RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} 

And it's working as expected but the same rule is not working for sub links, when I access existing links, like it will still load in http, no redirection happens for existing links.

Question Credit: Augustin
Question Reference
Asked October 10, 2018
Posted Under: Network
2 Answers

On shared hosting, when you don't have better options, you could modify your rewrite rule in the .htaccess:

RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

First, the RegEx at the beginning matches to all requests, including everything behind the domain.

Then, a HTTP Result code of 301 (moved permanently) is thrown back to the client together with the new URL. Most of the modern browsers remember the new URL, in this case the httpS, and redirect to the new url automatically the next time the user calls up the website.

I hope this helps, kind regards

credit: Sebastian
Answered October 10, 2018
Your Answer