StevenPHP
StevenPHP

Reputation: 3597

htaccess redirect only root domain

I would like to redirect my domain name from one site to another. I only want the rule to be applied if no other subpages are specified

EG:

www.example.com 

would get redirected

www.example.com/folder/page.php

would not get redirected

The code I have does a catch all and that is not what I want

RewriteCond %{HTTP_HOST} ^oldsite.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.oldsite.com [NC]
RewriteRule ^(.*)$ http://newsite.com/folder/$1 [L,R=301]

Upvotes: 2

Views: 8874

Answers (1)

anubhava
anubhava

Reputation: 784918

You can use:

RewriteCond %{HTTP_HOST} ^(www\.)?oldsite\.com [NC]
RewriteRule ^/?$ http://newsite.com/folder/ [L,R=301]

Upvotes: 8

Related Questions