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 need to rewrite both the REQUEST_URI and the HTTP_HOST but I'm getting a redirection error when I implement this:

# Capture mysite.com/pages/123
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]+).mysite.com
RewriteRule (.*) $1&subdomain=%1 [L,QSA]

What am I doing wrong here?

Thanks

share|improve this question

1 Answer 1

up vote 1 down vote accepted

I would try something like the following;

# This will map requests like 
# http://XXX.mysite.com/pages/123?somevar=someval&more=more2
# to /dir/pages.php?id=123&subdomain=XXX&somevar=someval&more=more2
RewriteCond %{HTTP_HOST} ^([a-z0-9]+).mysite.com
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

 
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.