Skip to content

Instantly share code, notes, and snippets.

@rosemckeon
Created December 16, 2013 12:12
Show Gist options
  • Save rosemckeon/7986061 to your computer and use it in GitHub Desktop.
Save rosemckeon/7986061 to your computer and use it in GitHub Desktop.
How to 301 with htaccess

How to redirect your site to a new domain name with htaccess

You can use a 301 redirect to notify search engines and browsers that your site has permanently moved to a new location. You'll need to have both domain names pointing to your hosting while everyone takes note of these changes. It will take time for Google to update your listings and for returning visitors to see the change. If they have your site bookmarked, their bookmark will update automatically.

The following can be added to the .htaccess file in the root of your public html files. This will point any page at the old domain to the same location on the new domain.

<IfModule mod_rewrite.c>
RewriteEngine on
Options +FollowSymlinks
RewriteCond %{HTTP_HOST} ^olddomain\.co\.uk$ [OR]
RewriteCond %{HTTP_HOST} ^www\.olddomain\.co\.uk$
RewriteRule ^(.*)$ "http\:\/\/www\.newdomain\.co\.uk\/$1" [R=301,L]
</IfModule>

Written with StackEdit.

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