基于语言变量重写.htaccess中的writerrule


RewriteRule in .htaccess based on language variable

我有一个网站,其中包含德语作为默认语言和英语作为替代语言。我想根据语言条件将我的rss url重定向到网站的另一个路径。

我的意思默认情况下为http://www.eample.com/rss.xml到http://www.eample.com/index.php?type=11在可选语言的情况下,从http://www.eample.com/en/rss.xml到http://www.eample.com/index.php?type=11&L=1

我已经用下面的方法尝试过了,但是它只尊重默认情况。

RewriteRule rss.xml$ /index.php?type=11 [L,R=301]
RewriteRule en/rss.xml$ /index.php?type=11&L=1 [L,R=301]

你们能帮我实现这个吗?

试试这个:

RewriteRule ^rss'.xml$ /index.php?type=11 [NC,L,R=301]
RewriteRule ^en/rss'.xml$ /index.php?type=11&L=1 [NC,L,R=301]

也许可以加入一些正则表达式来捕获额外的国家/语言代码。

RewriteRule ^rss'.xml$ /index.php?type=11 [NC,L,R=301]
RewriteRule ^(en|de|fr)/rss'.xml$ /index.php?type=11&L=$1 [NC,L,R=301]

或匹配任意两个字符

RewriteRule ^([a-z]{2})/rss'.xml$ /index.php?type=11&L=$1 [NC,L,R=301]