Skip to content

Instantly share code, notes, and snippets.

@schilke
Last active August 29, 2015 14:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schilke/79b0cb87b3bb93a7c309 to your computer and use it in GitHub Desktop.
Save schilke/79b0cb87b3bb93a7c309 to your computer and use it in GitHub Desktop.
Redirect rules on change of domain name
# Redirect all requests from olddomain.com to www.newdomain.com
# tell the server to activate mod_rewrite
RewriteEngine On
# What's the redirect base (i.e. root or subdirectory)
RewriteBase /
# Either check if the request goes to the old domain
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
# Just in case you want to redirect any subdomain as well
# uncomment the following line
# RewriteCond %{HTTP_HOST} ^(.*\.)?olddomain\.com$ [NC]
# or - as a more general alternative - check if the request does
# _not_ go to the _new_ domain (just comment/uncomment the condition)
# RewriteCond %{HTTP_HOST} !^(www\.)?newdomain\.com$ [NC]
RewriteRule .* http://www.newdomain.com%{REQUEST_URI} [R=301,L]
# Redirect end
@schilke
Copy link
Author

schilke commented Jan 20, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment