[英].htaccess - Matching Env Variables in Rewrite Rule
I am trying to match the words 'blogs' and 'news' in the following url
according to the detected language via htaccess
. 我试图根据通过
htaccess
检测到的语言在以下url
匹配单词'blogs'和'news'。
the url: 网址:
http://localhost/es/noticias
the language detection (working): 语言检测(工作):
RewriteCond %{HTTP_HOST} ^(es)\. [OR]
RewriteCond %{REQUEST_URI} .*/(es)/.*
RewriteRule ^(.*) - [E=LANG:%1,E=NEWS:noticias,E=BLOGS:blogs]
the rule (not matching ENV:BLOGS nor ENV:NEWS) 规则(与ENV:BLOGS或ENV:NEWS不匹配)
RewriteRule ^([^\/]+/)?(%{ENV:BLOGS}|%{ENV:NEWS}) index.php?vd=%{ENV:LANG}/$1&m=$2 [NC,QSA,L]
How to match Env Variables in Rewrite Rule
? 如何在
Rewrite Rule
匹配环境变量 ?
EDIT 1 - the extended language translation 编辑1-扩展语言翻译
RewriteCond %{HTTP_HOST} ^(es)\. [OR]
RewriteCond %{REQUEST_URI} .*/(es)/.*
RewriteRule ^(.*) - [E=LANG:%1,E=NEWS:noticias,E=BLOGS:blogs]
RewriteCond %{HTTP_HOST} ^(en)\. [OR]
RewriteCond %{REQUEST_URI} .*/(en)/.*
RewriteRule ^(.*) - [E=LANG:%1,E=NEWS:news,E=BLOGS:blogs]
RewriteCond %{HTTP_HOST} ^(fr)\. [OR]
RewriteCond %{REQUEST_URI} .*/(fr)/.*
RewriteRule ^(.*) - [E=LANG:%1,E=NEWS:nouvelles,E=BLOGS:blogosphere]
Rather than RewriteRule
you need to use RewriteCond
for matching env variables. 您需要使用
RewriteCond
而不是RewriteRule
来匹配环境变量。 See this code snippet: 请参见以下代码段:
RewriteCond %{ENV:BLOGS} ^blogs$ [OR]
RewriteCond %{ENV:NEWS} ^noticias$
# some RewriteRule here
RewriteRule ^ - [L]
RewriteRule
on the other hand is used for matching request URI only. 另一方面,
RewriteRule
仅用于匹配请求URI。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.