Sign up ×
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 and directed to a different root directory.

so and 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.


ServerAlias *

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} !$ [NC]
RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+) [NC]
RewriteRule (.*) %2/other_folder/$1 [L]

Which would redirect anything but and to another folder.


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

<virtualhost *:80>
    DocumentRoot /var/www/example

<virtualhost *:80>
    ServerAlias *
    DocumentRoot /var/www/another_example_root_folder

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.… – Prix Aug 30 '10 at 20:56

Your Answer


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.