Created
July 26, 2016 00:47
-
-
Save Sija/fe434bb19026e972ae353c34e93c4582 to your computer and use it in GitHub Desktop.
no-www mod_rewrite apache .htaccess redirect
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 | |
# Preserve HTTP/HTTPS protocol in .htaccess redirects | |
# http://stackoverflow.com/a/20419821/601064 | |
RewriteCond %{HTTPS} =on | |
RewriteRule ^(.*)$ - [env=proto:https] | |
RewriteCond %{HTTPS} !=on | |
RewriteRule ^(.*)$ - [env=proto:http] | |
# Rewrite "www.example.com -> example.com" | |
# http://stackoverflow.com/a/2361618/601064 | |
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] | |
RewriteRule ^ %{ENV:proto}://%1%{REQUEST_URI} [R=301,L] | |
</IfModule> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment