mod_rewrite:url重写同时加上子域名(通配符)重写
我的 .htaccess 文件中有两条用于 URL 重写的规则:
用于子域重写:
xxx.domain.com
在内部重定向到file.php?项目=xxx
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC] RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.domain\.com$ [NC] RewriteRule ^$ /file.php?item=%2 [QSA,nc]
普通重写:
RewriteRule ^([A-Za-z0-9_)(:!-',]+)/?$ file.php?item=$1 [L]
我需要实现的是编写第三条规则,它将结合这两个规则而不与它们发生冲突。也就是说,在这行下面(或上面)我需要有类似的东西:
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.domain\.com/([A-Za-z0-9_)(:!-',]+)$ [NC]
RewriteRule ^$ /anotherfile.php?item1=%2&item2=$1 [QSA,nc]
这样 http://xxx.domain .com/yyy 将被重定向到 anotherfile.php?item1=xxx&item2=yyy
任何可行的想法,或者正确的方法是什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试此规则:
它使用第一个规则的条件和第二个规则的 URL 路径模式。
Try this rule:
It uses conditions of the first rule and URL path pattern of the second.