与子域名和URL模式mod_rewrite的 [英] mod_rewrite with subdomain and url pattern
问题描述
我要使用的子域与mod_rewrite的一个变量获得并使用一些参数:
I want to use the subdomain as a get variable with mod_rewrite AND use some parameter :
例如 /页/语言/网站/计数器
- > 的index.php O =运营商和放大器; LG =语言和放大器; S = ARG1和C? = ARG2
如何做到这一点与mod_rewrite的?
How to do that with mod_rewrite?
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST} ^([a-zA-Z]{3,6})\.example\.com
RewriteRule ^index/([a-z]{2})/([0-9]{1,2})/([0-9]{1,2})$ http://www.example.com/index.php?o=%1&lg=%2&site=%3&counter=%4 [NC,L] # for index.php
RewriteRule ^export/([a-z]{2})/([0-9]{1,2})/([0-9]{1,2})$ http://www.example.com/export.php?o=%1&lg=%2&site=%3&counter=%4 [NC,L] # for export.php
任何想法?
在此先感谢
推荐答案
A 的RewriteCond
也只属于直接下重写规则
。所以你的情况这两种的RewriteCond
指令就只属于第一个重写规则
指令与第二重写规则
没有关联的的RewriteCond
指令。
A RewriteCond
does only belong to the directly following RewriteRule
. So in your case both RewriteCond
directives do only belong to the first RewriteRule
directive and the second RewriteRule
has no associated RewriteCond
directives.
您可以通过合并在你的榜样,解决这个问题的两个重写规则
取值:
You can fix this in your example by merging the two RewriteRule
s:
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([a-zA-Z]{3,6})\.example\.com$
RewriteRule ^(index|export)/([a-z]{2})/([0-9]{1,2})/([0-9]{1,2})$ http://www.example.com/$1.php?o=%1&lg=$2&site=$3&counter=$4 [NC,L]
另外要注意的 $ N
而不是%N
为 $ N使用
指重写规则
的,而%N
指的是第n个组的比赛的第n个组的比赛最后一次成功的RewriteCond
。
Also note the usage of $n
instead of %n
as $n
refers to the match of the n-th group of RewriteRule
the while %n
refers to the match of the n-th group of the last successful RewriteCond
.
这篇关于与子域名和URL模式mod_rewrite的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!