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

I am trying to create a dynamic subdomain and I am having great difficulty, I keep getting 500 Internal Server Error

So for example the actual domain should be

which should point/redirect

However when I access this URL I get an Internal Server Error (500), any ideas?

The vhost.conf holds

ServerAlias *

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{HTTP_HOST} !$ [NC]
RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+) [NC]

RewriteRule (.*)$1 [L]

I am using, Redhat Linux, With Plesk

share|improve this question

migrated from Jan 4 '12 at 15:12

This question came from our site for professional and enthusiast programmers.

1 Answer 1

up vote 2 down vote accepted

(I have answered a post like that not so long ago, although here the situation differs a little)

Say someone goes to This matches both conditions.

The main problem: your rewrite rule matches an empty input...

So, goes through the rule and becomes

And then it goes back to the server again, and matches again both conditions. The URL becomes

Have you noticed? It substitute with the value of the request, not what you captured in your second RewriteCond, and there lies your other problem.

You can reuse groups captured by RewriteCond but they are preceded with %, not $. Hence, what you want really is this (with full regex metacharacters etc plus anchors):

RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
# Non capturing group for "www." if present: it is of no interest
RewriteCond %{HTTP_HOST} ^(?:www\.)([a-z0-9-]+)\.domain\.com$ [NC]
RewriteRule (.*)$1 [L] # Note the %!
share|improve this answer

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.