Redirect all Pages from Old Domain to New Domain Using .htaccess

Support this website by purchasing prints of my photographs! Check them out here.

You can put the following .htaccess document in the root of your domain to redirect all pages from a domain to a new one. This is useful if you are keeping existing content from an old domain, but are moving all of the pages to a new one.

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]

The type of redirect used here, 301, means it is a permanent redirect. If the move is only temporary, you will want to use a 302 instead.

Also, if you have some files on the old domain which you still want to be accessible, you can use the following .htaccess file. It does the same thing, but if a URL is requested for a file which still exists, it serves that up instead.

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
Thomas Hunter II Avatar

Thomas has contributed to dozens of enterprise Node.js services and has worked for a company dedicated to securing Node.js. He has spoken at several conferences on Node.js and JavaScript and is an O'Reilly published author.