I have been looking around for a snippet of code that will force https://
. I've found this:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
The problem is when I want to work on local so a url like "localhost" or "example.dev" it tries to redirect to https://localhost
(it doesn't work).
How do I solve this?
(so to sum it all up, I want the snippet above to work only when I use it on production, e.g "example.com")
I want the snippet above to work only when I use it on production, e.g
example.com
)
You can restrict your rule to only target example.com
using a rewrite condition:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,NE,R=301]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With