This question already has an answer here:

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]

marked as duplicate by HopelessN00b, Jenny D, mdpc, Ward, Falcon Momot Feb 8 '14 at 11:40

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 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 6 '14 at 14:34

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]


RewriteRule ^.* http://www.example.com/ [L,R=302]
  • 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 6 '14 at 14:36

Not the answer you're looking for? Browse other questions tagged or ask your own question.