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

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 is the author of Advanced Microservices and is a prolific public speaker with a passion for reducing complex problems into simple language and diagrams. His career includes working at Fortune 50's in the Midwest, co-founding a successful startup, and everything in between.