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.

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

http://www.parameterToBePassed.domain.com/

which should point/redirect

http://www.domain.com/shopping/gatename/parameterToBePassed

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

The vhost.conf holds

ServerAlias www.domain.com domain.com *.domain.com

<IfModule mod_rewrite.c>
RewriteEngine On

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

RewriteRule (.*) http://www.domain.com/shopping/gatename/$1 [L]
</IfModule>

I am using, Redhat Linux, With Plesk

share|improve this question

migrated from stackoverflow.com Jan 4 '12 at 15:12

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

add comment

1 Answer

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 a.domain.com. This matches both conditions.

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

So, a.domain.com goes through the rule and becomes a.domain.com/shopping/gatename/.

And then it goes back to the server again, and matches again both conditions. The URL becomes a.domain.com/shopping/gatename/shoppin/gatename/.

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 (.*) http://www.domain.com/shopping/gatename/%1/$1 [L] # Note the %!
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.