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

I need to rewrite both the REQUEST_URI and the HTTP_HOST but I'm getting a redirection error when I implement this:

# Capture
RewriteCond %{REQUEST_URI} ^/pages/[0-9]+/?$
RewriteRule ^/pages/([0-9]+)/?$ /home/mysite/www/pages.php?id=$1
# Now capture the subdomain
RewriteCond %{HTTP_HOST} ^([a-z0-9]+)
RewriteRule (.*) $1&subdomain=%1 [L,QSA]

What am I doing wrong here?


share|improve this question
up vote 1 down vote accepted

I would try something like the following;

# This will map requests like 
# to /dir/pages.php?id=123&subdomain=XXX&somevar=someval&more=more2
RewriteCond %{HTTP_HOST} ^([a-z0-9]+)
RewriteRule ^/pages/([0-9]+)$ /dir/pages.php?id=$1&subdomain=%1 [L,QSA]

The first RewriteCond on %{REQUEST_URI} is probably unnecessary, because it contains the path component of the requested URI, which is already available in the RewriteRule Pattern match.

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.