Last active
August 29, 2015 14:16
-
-
Save sidisinsane/7c7ee71800169c8e791b to your computer and use it in GitHub Desktop.
generic force www (incl. subdomains) and non-www
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
######################################################################################## | |
# store requested protocol in %{ENV:protocol} | |
######################################################################################## | |
RewriteCond %{HTTPS} =on | |
RewriteRule ^(.*)$ - [env=protocol:https] | |
RewriteCond %{HTTPS} !=on | |
RewriteRule ^(.*)$ - [env=protocol:http] | |
######################################################################################## | |
# force non www | |
######################################################################################## | |
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] | |
RewriteRule ^(.*)$ %{ENV:protocol}://%1/$1 [R=301,L] | |
######################################################################################## | |
# force www (including subdomains) | |
######################################################################################## | |
RewriteCond %{HTTP_HOST} !^www\. [NC] | |
RewriteCond %{HTTP_HOST} (.*) | |
RewriteRule (.*) %{ENV:protocol}://www.%1/$1 [R=301,L] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment