多个规则集的在.htaccess单一的RewriteCond [英] Multiple RewriteRules for single RewriteCond in .htaccess

查看:403
本文介绍了多个规则集的在.htaccess单一的RewriteCond的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的.htaccess以下命令

I have following command in my .htaccess

    RewriteCond %{HTTP_HOST} ^(www\.)?([a-z0-9-]+)\.example\.com [NC]
    RewriteRule ^(.*?)-([a-z]+) %2/$1.$2 [L]
    RewriteRule ^(.*?)-([0-9]+)([a-z]) %2/$1$3.$2 [L]

%2不是工作在第二个和以后行。 我可以定义任何变量%2,并用它在所有重写规则的命令? 下面的命令作品

%2 is not working in second and later lines. Can I define any variable for %2 and use it in all RewriteRule commands? Following command works

     RewriteCond %{HTTP_HOST} ^(www\.)?([a-z0-9-]+)\.example\.com [NC]
     RewriteRule ^(.*?)-([a-z]+) %2/$1.$2 [L]
     RewriteCond %{HTTP_HOST} ^(www\.)?([a-z0-9-]+)\.example\.com [NC]
     RewriteRule ^(.*?)-([0-9]+)([a-z]) %2/$1$3.$2 [L]

不过,我想用2%用于多个规则行不重复的条件。

But I want use %2 for multiple rule line without duplicating condition.

推荐答案

变量必须被保存为一个Apache VAR,那么可以不使用重复的条件。

The variable must be saved as an Apache var, then that can be used without repeated conditions.

保存在Apache的变量显示在第二行。用法3届和第4行保存瓦尔的。

Saving in Apache variables are shown in second line. Usage of saved vars in 3th and 4th lines.

RewriteCond %{HTTP_HOST} ^(www\.)?([a-z0-9-]+)\.example\.com [NC]
RewriteRule .? - [E=Wa:%1,E=Wb:%2]
RewriteRule ^(.*?)-([a-z]+) %{ENV:Wb}/$1.%{ENV:Wb} [L]
RewriteRule ^(.*?)-([0-9]+)([a-z]) %{ENV:Wb}/$1$3.$2 [L]

这篇关于多个规则集的在.htaccess单一的RewriteCond的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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