Last active
December 22, 2015 07:08
-
-
Save breenie/6435611 to your computer and use it in GitHub Desktop.
Useful mod_rewrite snippets
This file contains hidden or 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
| RewriteEngine on | |
| # Redirect from anyhost to www | |
| RewriteCond %{HTTP_HOST} !^www\.example\.com [NC] | |
| RewriteCond %{HTTP_HOST} !^$ | |
| RewriteRule ^/?(.*) http://www.example.com/$1 [L,R,NE] | |
| # Remove www from the request uri | |
| RewriteCond %{HTTP_HOST} ^www\. | |
| RewriteCond %{HTTPS}s ^on(s)|off | |
| RewriteCond http%1://%{HTTP_HOST} ^(https?://)(www\.)?(.+)$ | |
| RewriteRule ^ %1%3%{REQUEST_URI} [R=301,L] | |
| # Redirect a particular host to somewhere else | |
| RewriteCond %{HTTP_HOST} ^([a-z.]+)?othersite\.com [NC] | |
| RewriteRule ^/?(.*) http://www.example.com/dir [L,R,NE] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment