Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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 have two rules in my .htaccess file for url rewriting:

  1. for subdomain rewriting: is internally redirected to file.php?item=xxx

    RewriteCond %{HTTP_HOST} !^$ [NC]

    RewriteCond %{HTTP_HOST} ^(www.)?([^.]+)$ [NC]

    RewriteRule ^$ /file.php?item=%2 [QSA,nc]

    2.ordinary rewriting:

    RewriteRule ^([A-Za-z0-9_)(:!-',]+)/?$ file.php?item=$1 [L]

What i need to achieve is writing a third rule that will combine these two rules without being in conflict with them. Namely, below (or above) this lines i need to have something like that

RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.domain\.com/([A-Za-z0-9_)(:!-',]+)$ [NC]

RewriteRule ^$ /anotherfile.php?item1=%2&item2=$1 [QSA,nc]

so that will be redirected to anotherfile.php?item1=xxx&item2=yyy

any ideas that will work, or what is the correct way of it?

share|improve this question

You may be close, but HTTP_HOST only contains the hostname (I think), not the URI, which is in REQUEST_URI. Combining the two should give you what you want:

RewriteCond %{HTTP_HOST}%{REQUEST_URI} ^.....$
share|improve this answer

Your Answer


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