Redirect Everything Except Root Page with .htaccess

Recently, I moved my website to a different domain. For good SEO, we should redirect everything, including path to a new domain.

However, due to some reason, I need to maintain the root (index page) page, but I can redirect all other URL from the old to a new domain.

To do this, I have to edit the .htaccess file in the root domain & add the following code. Remember to replace “yourolddomain” & “yournewdomain” with your domain name before using it.

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?yourolddomain\.com$ [NC]
RewriteRule ^.+$ http://yournewdomain.com%{REQUEST_URI} [L,R=301]


0 comments… add one

Leave a Comment