Our application needs to redirect HTTP requests to HTTPS.
Normally i would use the RewriteCond as below.
RewriteCond %{HTTPS} off
The thing with our current hosting company is that the requested port is always 80. It doens't matter if we send a HTTP or HTTPS request, the $_SERVER['SERVER_PORT'] is always 80.
We can handle this in PHP, but we also want to force files to HTTPS.
So the concrete question. Is there anyway to force HTTPS in .htaccess without using RewriteCond like RewriteCond %{HTTPS} or RewriteCond %{SERVER_PORT}.
Your situation is not that uncommon. Try this (X-Forwarded-Proto is de facto standard for identifying the originating protocol of an HTTP request):
RewriteCond %{HTTP:X-Forwarded-Proto} !https [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
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