Skip to content

Instantly share code, notes, and snippets.

@larsschenk
Created November 29, 2010 12:10
Show Gist options
  • Save larsschenk/719886 to your computer and use it in GitHub Desktop.
Save larsschenk/719886 to your computer and use it in GitHub Desktop.
Rewrite rule in apache config to allow only specific server names.
# Allow only www.domain.com and www2.domain.com.
# Redirect all other server alias names to the main name.
# SEO: To avoid "duplicate content" you should have only one allowed server name.
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC] [OR]
RewriteCond %{HTTP_HOST} !^www2\.domain\.com [NC] [OR]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) http://www.domain.com/$1 [L,R=permanent]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment