Redirect Only Root Directory or Index Page with .htaccess

Previously, we looked at on how to Redirect Everything Except Root Page with .htaccess.

I have another domain where I need to redirect only root directory or index of the domain but not the sub-directory. You may need this is you have cPanel & you need to redirect the main domain without affecting your add-on 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
RewriteCond %{HTTP_HOST} yourolddomain\.com [NC]
RewriteCond %{REQUEST_URI} ^/$
Rewriterule ^(.*)$ http://yournewdomain.com/ [L,R=301]


0 comments… add one

Leave a Comment