Last active
December 29, 2015 14:29
-
-
Save benbridge/7684484 to your computer and use it in GitHub Desktop.
Rules to force www or no 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
<IfModule mod_rewrite.c> | |
RewriteEngine on | |
# Set "protossl" to "s" if we were accessed via https://. | |
RewriteRule ^ - [E=protossl] | |
RewriteCond %{HTTPS} on | |
RewriteRule ^ - [E=protossl:s] | |
# To redirect all users to access the site WITH the 'www.' prefix, | |
# (http://example.com/... will be redirected to http://www.example.com/...) | |
RewriteCond %{HTTP_HOST} . | |
RewriteCond %{HTTP_HOST} !^www\. [NC] | |
RewriteRule ^ http%{ENV:protossl}://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] | |
# To redirect all users to access the site WITHOUT the 'www.' prefix, | |
# (http://www.example.com/... will be redirected to http://example.com/...) | |
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] | |
RewriteRule ^ http%{ENV:protossl}://%1%{REQUEST_URI} [L,R=301] | |
</IfModule> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment