mod_rewrite: url rewriting plus subdomain (wildcard) rewrite at the same time
I have two rules in my .htaccess
file for url rewriting:
for subdomain rewriting:
xxx.domain.com
is internally redirected tofile.php?item=xxx
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC] RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.domain\.com$ [NC] RewriteRule ^$ /file.php?item=%2 [QSA,nc]
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 http://xxx.domain.com/yyy will be redirected to anotherfile.php?item1=xxx&item2=yyy
any ideas that will work, or what is the correct way of it?
Try this rule:
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.example\.com$ [NC]
RewriteRule ^([A-Za-z0-9_)(:!-',]+)/?$ /file.php?item1=%2&item2=$1 [QSA]
It uses conditions of the first rule and URL path pattern of the second.
精彩评论