与子域名和URL模式mod_rewrite的 [英] mod_rewrite with subdomain and url pattern

查看:202
本文介绍了与子域名和URL模式mod_rewrite的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要使用的子域与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 RewriteRules:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆