Created
February 9, 2012 14:00
-
-
Save felipelavinz/1780150 to your computer and use it in GitHub Desktop.
Canonical redirects for Apache, lighttpd and nginx
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
## Canonical redirect for Apache | |
# BEGIN Canonical Redirect | |
<IfModule mod_rewrite.c> | |
RewriteEngine On | |
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC] ## will match any domain that's not our main domain | |
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L] | |
</IfModule> | |
# END Canonical 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
## Canonical redirect for lighttpd | |
$HTTP["host"] == "domain.com" { | |
url.redirect = ( | |
"^/(.*)" => "http://www.domain.com/$1" | |
) | |
} | |
# for various domains | |
$HTTP["host"] =~ "(domain.com|domain1.com|domain2.com)" { | |
url.redirect = ( | |
"^/(.*)" => "http://www.domain.com/$1" | |
) | |
} |
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
## Canonical redirect for ngingx | |
# as separate vhost rules | |
server { | |
listen 80; | |
server_name domain.com; # add other domains separated by a space as necessary | |
rewrite ^/(.*)$ http://www.domain.com/$1 permanent; | |
} | |
# as a condition on an existent vhost | |
server { | |
listen 80; | |
server_name www.domain.com domain.com domain2.com www.domain2.com | |
if ( $host != 'www.domain.com' ) { | |
rewrite ^/(.*)$ http://www.domain.com/$1 permanent; | |
} | |
# ... other vhost configs | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you.