Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

On my site i rewrite all my domains to the root such as


I also have a few before it which all work (there are all simple and only specify a DocumentRoot)

Now the problem is i have a complex VirtualHost. Its like 16lines. I have a ServerAlias however apache never uses it because it uses the * rule and rewrites instead of using that virtaulhost specifying a specific subdomain.

How do i solve this? is there an option i can use that uses wildcards last? or choose the ordering of the files it looks at? or do i need to copy/paste the virtualhost into that other file?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

It will be the first VirtualHost that matches which will be loaded, and since the files are loaded in alphabetical order, you can change the ordering by changing the filenames.

What I do is put a number prefix for each filename so I can set the priority in order to do something like what you mention. e.g.:

share|improve this answer
hmm, problem. i have 4 sites enabled. Call then c, d, e and z. z is zrewrite which is for domains and subdomains i dont serve (its mono's default test page). For this host i dont specify a server name or alias. 2 of the 3 sites work, the one that doesnt is C which should be the first loaded. I use its server alias to test the page (i need to buy the official domain soon). The alias is This site keeps using the default unless i disable zrewrite. and when i do, it does work but then both and serveripaddr runs that site. Why is it doing this? – acidzombie24 Dec 28 '10 at 4:18
i know i didnt mistype the alias name as i copy/pasted it to my browser. works so i dont know why doesnt. – acidzombie24 Dec 28 '10 at 4:19
I did more testing and looked up apache docs. apparently the first virtual host is default so i made aFirst and put the dummy in there. Your answer already solved the rewrite ordering problem but i cant get the default page working. Even after aFirst, zLast and all my sites in between the default (i test by using my servers ip addr) and is ALWAYS the same even (it seems to be randomly choosen every time i restart apache. -edit- Actually not so random. Its every other time). – acidzombie24 Dec 28 '10 at 4:53
I made its own question… – acidzombie24 Dec 28 '10 at 5:03

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.