Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I would like any directory *.example.com (bar.example.com, foo.example.com, etc..) to direct to the folder /home/user/htdocs/subdir/

www.example.com and example.com should remain unaffected.

Is this possible with htacecss, or another route?

share|improve this question

2 Answers 2

You could do this by setting up two virtual hosts via the Apache configuration. For example:

NameVirtualHost *:80

<VirtualHost *:80>
  DocumentRoot /home/user/htdocs
  ServerName www.example.com example.com
</VirtualHost>

<VirtualHost *:80>
  DocumentRoot /home/user/htdocs/subdir
  ServerName *.example.com
</VirtualHost>
share|improve this answer

After the declaring in your Apache configuration file the directives for www.example.com and example.com, you can set an extra VirtualHost entry with any subdomain as ServerName and a wildcard ServerAlias like so to point every subdomain there.

<VirtualHost *:80>
  DocumentRoot /home/user/htdocs/subdir
  ServerName foobar.example.com
  ServerAlias *.example.com
</VirtualHost>

Note: You must declare a servername (any would do)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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