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.

Is there a best practice (for performance reasons or otherwise) for choosing between using a Virtual Host or rewrite for pointing a subdomain to a folder in the root directory?

I.e.,

www.domain.com -> public_html/domain.com/
sub.domain.com -> public_html/sub.domain.com/

The above can be accomplished by setting up two virtual hosts or by using a single virtual host and just having a rewrite set up to point to the correct sub directory.

My question originally concerned Apache, but I would be interested in knowing if there's a best practice for Nginx's Server Block as well.

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

I'd use two virtual hosts because rewriting tends to get messy pretty fast.

share|improve this answer
add comment

Rewrite the subdomain should be faster because it does not need to go and read the configuration of your virtual host, still , might be miliseconds (unless the apache is not working well), otherwise I think the best is to do it in a virtual host,due you can manage it from a better way and you dont need to wait for refresh.

share|improve this answer
1  
Not convinced. If you do a rewrite in .htaccess that'll be slower. If you do it in the apache config it still needs to be read and might generate an internal second request - depending on the nature of the redirect. –  Steve Kemp Sep 11 '12 at 13:36
add comment

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.