[SSL-Guide] https via .htaccess

Avast

Founder license
License owner
Joined
Apr 11, 2011
Messages
243
Points
100
Location
Hamburg, Germany
Website
share-pic.net
This tutorial describes, how to use https (SSL) via .htaccess. (I prefer the solution via v-hosts, but if you don't have access to it you have to use .htaccess)

There are 3 solutions for https via .htaccess

1.) Insert this two lines to your .htaccess-file:
Code:
RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
2.) If you want to bind it at the ssl-port:
Code:
RewriteCond %{SERVER_PORT} !^443$
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
3.) To redirect all http-requests to https use this:
Code:
RewriteCond %{SERVER_PORT} ^80$
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
 
Reactions: Rodolfo

tomsit

Moderator & Chevereto freak
Community Staff
Joined
Nov 25, 2016
Messages
494
Points
145
Location
Norway
Website
freeimage.host
How to redirect to HTTPS using .htaccess behind Nginx Proxy

Code:
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{SERVER_NAME}/$1 [R,L]