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

I want to have anything other than www.example.com and example.com directed to a different root directory.

so example.com and

example.com/page will be going to two seperate roots.

i need to do this so i can have the home page directed elsewhere while under development.

here is what my vhost for the site looks like.

ServerName www.example.com

ServerAlias *.example.com



DocumentRoot /var/www/example   

share|improve this question

1 Answer 1

Try this on your .htaccess file at /var/www/example:

RewriteEngine on
RewriteCond %{HTTP_HOST} !www.example.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+).example.com [NC]
RewriteRule (.*) %2/other_folder/$1 [L]

Which would redirect anything but www.example.com and example.com to another folder.

OR

To actually have a different DocumentRoot you would need to create a new VirtualHost, you could try for example:

<virtualhost *:80>
    ServerName www.example.com
    ServerAlias example.com
    DocumentRoot /var/www/example
</virtualhost>

<virtualhost *:80>
    ServerName anything.example.com
    ServerAlias *.example.com
    DocumentRoot /var/www/another_example_root_folder
</virtualhost>

So your first virtualhost would take only with and without www and the second anything else.

share|improve this answer
    
I tried the first method you mentioned with no luck i ended up getting this fixed by doing it in the php thanks anyways –  user52177 Aug 30 '10 at 20:47
    
@user52177 Yes you can do that with a php aswell, anyway glad you got it working you might want to add your php code on a new answer and mark it as the solution to your question as it may also help others with the same problem. meta.stackexchange.com/questions/5234/… –  Prix Aug 30 '10 at 20:56

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.