-1

I would like to redirect my root domain to another site, but leave the subdomains in tact.

so redirect mydomain.com to mydomain.com/directory, but leave alone subdomain.mydomain.com.

Will this work? or will it also redirect subdomains.

RewriteEngine on RewriteCond %{HTTP_HOST} ^mydomain.com$ [NC] RewriteRule ^(.*)$ http://example.com/directory$1 [R=301,L]

albo
  • 51
  • 1
  • 7
  • No. This link is talking about leaving alone sub directories I want to leave subdomains alone not subdirectories. Sub directories should if they are on root. – albo Feb 06 '14 at 14:34

1 Answers1

3

Try this

RewriteEngine On
# Redirect anything except foo.example.com, bar.example.com

RewriteCond %{HTTP_HOST} !^(foo|bar)\.example\.com$ [NC]

# Redirect to www.example.com, preserving the URI
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=302]

or 

RewriteRule ^.* http://www.example.com/ [L,R=302]
iOflower
  • 46
  • 2
  • This answers my question but is there anyway to leave alone all subdomains without explicitly writing them (foo|bar), there are many subdomains and they are constantly added so I do not want to have to keep updating the .htaccess every time I add a subdomain. – albo Feb 06 '14 at 14:36