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

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My httpd.conf looks like this:


DocumentRoot /var/www/html/site

 <IfModule mod_rewrite.c>
    RewriteEngine On

DocumentRoot /var/www/html/blog

Listen *:2194

<VirtualHost *:2194>
   Redirect /

I want to be able to enable 'categories' as subdomains, ie if a user accesses:

It should show him that URL itself, but show him the contents of

It does not have to be a generic / wildcard based approach - these categories will be a small number that I can specify individually. I just dont want whatever I add to interfere with the existing functioning of the site.

How can I do this?

share|improve this question
up vote 2 down vote accepted


ServerAlias *

to the vhost and employ these rewrite rules:

Options +FollowSymLinks 
RewriteEngine on
RewriteCond %{HTTP_HOST} !^(www)\. [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.example\.com [NC]
RewriteRule (.*) [R=301,L]

If you already have a subdomain, eg., explicitly set as ServerName/ServerAlias for another vhost, it will take precedence over the wildxard vhosts

share|improve this answer
Hi. If I want specifically for it to react on - how do I do that? – siliconpi Dec 28 '11 at 16:11
Add ServerAlias instead, and change the first Rewrite Condition to: RewriteCond %{HTTP_HOST} ^(science)\. [NC]. This way you're saying "If the hostname starts with science then:" instead of the first example where the condition is true everytime the hostname "does NOT start with www " – Mathias R. Jessen Dec 28 '11 at 16:46
If you don't want anyone to access your site (and get redirected), from other hostnames than the www and the few subdomains you specify, I would probably go with the "wildcard" rewrite rules, where you rewrite all requests that does NOT start with "www", and then ONLY add the subdomains needed as ServerAlias's – Mathias R. Jessen Dec 28 '11 at 16:49
Hmm - thanks for responding... I'm trying the original and OpenDNS is redirecting me to its own page. The domain is registered at one place and the hosting is at the other. Do I need to add any DNS entries? – siliconpi Dec 28 '11 at 16:52
Yeah, create a CNAME record for each subdomain and point them to the www. subdomain – Mathias R. Jessen Dec 28 '11 at 17:52

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.