Last active
November 25, 2019 07:05
-
-
Save akroii/693d9ba085e533d6a8fc47c2848264e2 to your computer and use it in GitHub Desktop.
Redirect to SSL, based on a condition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#works sometimes | |
RewriteCond %{HTTPS} off | |
RewriteCond %{HTTP_HOST} vvvvvv\.de$ [NC] | |
RewriteRule ^https://www.vvvvvv.de%{REQUEST_URI} [R=301,L,NE] | |
#redirect SPECIFIC host | |
RewriteCond %{HTTP_HOST} ^vvvvvv\.de [NC] | |
RewriteCond %{HTTPS} off | |
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} | |
#alternative | |
RewriteEngine On | |
RewriteCond %{HTTPS} !=on | |
RewriteRule ^https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] | |
#force redirect to https with www | |
RewriteEngine On | |
RewriteCond %{HTTPS} off | |
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] | |
RewriteCond %{HTTP_HOST} !^www\. [NC] | |
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] | |
RewriteCond %{HTTPS} off | |
RewriteCond %{HTTP_HOST} ccc\.de$ [NC] | |
RewriteRule ^https://www.cccc.de%{REQUEST_URI} [R=301,L,NE] | |
#redirect http non-www to www with https | |
RewriteCond %{HTTPS} off | |
RewriteCond %{HTTP_HOST} ^(www.)?example.com$ | |
RewriteRule (.) example.com/$1 [R=301,L] | |
#redirect https non-www to www | |
RewriteCond %{HTTPS} on | |
RewriteCond %{HTTP_HOST} ^example.com$ | |
RewriteRule (.) example.com/$1 [R=301,L] | |
# Contao 4.4 | |
RewriteCond %{HTTP_HOST} ^website\.de [NC] | |
RewriteRule (.*) https://www.website.de/$1 [R=301,L] | |
#ssl | |
RewriteCond %{HTTPS} !=on | |
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L] | |
RewriteCond %{REQUEST_FILENAME} !-f | |
RewriteRule ^(.*)$ app.php [QSA,L] | |
#Contao 4.4 alternative | |
RewriteCond %{HTTP:X-Forwarded-Proto} !https | |
RewriteRule ^(.*)$ https://%{SERVER_NAME}/$1 [R,L] | |
### wordpress | |
RewriteEngine On | |
RewriteCond %{HTTPS} off | |
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] | |
#redirect http non-www to www | |
RewriteCond %{HTTPS} off | |
RewriteCond %{HTTP_HOST} ^(www.)?example.com$ | |
RewriteRule (.) example.com/$1 [R=301,L] | |
#redirect https non-www to www | |
RewriteCond %{HTTPS} on | |
RewriteCond %{HTTP_HOST} ^example.com$ | |
RewriteRule (.) example.com/$1 [R=301,L] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
#redirect http non-www to https://www
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule (.) https://www.example.com/$1 [R=301,L]
#redirect https non-www to www
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule (.) https://www.example.com/$1 [R=301,L]