如何使用 .htaccess 进行多个重写规则?
我正在尝试使用 Drupal 建立一个多语言网站。
我喜欢使用以下网址格式
http://domain/[language]/[node id]
,
因此我将以下规则添加到.htaccess以进行测试
RewriteRule ^jpn/[0 -9]$ jpn.html
问题是规则被下面的规则覆盖
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
怎么办我有多个重写规则吗?
I am trying to build a multilingual website with Drupal.
I like to have the following url format
http://domain/[language]/[node id]
so I added the following rule to .htaccess for testing purpose
RewriteRule ^jpn/[0-9]$ jpn.html
The problem is that the rule is overwritten by the following rule
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
How do I have multiple rewrite rules?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的第二个
RewriteRule
具有L 标志
设置,这意味着如果规则匹配,则不会处理进一步的规则。如果您希望第一条规则也停止任何进一步的处理,请也向其中添加 L 标志。
还要确保您的第二条规则列在最后,因为它与所有内容 (.*) 匹配,因此 Apache 在它之后将永远不会看到任何其他规则。
编辑:L 旗 URL
Your second
RewriteRule
has theL Flag
set, which means that if the rule matches, no further rules will be processed.If you want your first rule to also stop any further processing, add the L Flag to it as well.
Also make sure that your second rule is listed last, because it matches everything (.*) and thus, Apache will never see any other rule after it.
Edited: the L Flag URL
我不确定这个 [L] 在每种情况下是否真的有效,以避免相互覆盖。我不是这方面的专家,但我花了一天的时间才发现,你只需要向之前有效的 RewriteRule 添加 1 个 Atome,而不会被覆盖,并且它会从第一个开始再次被覆盖。我很难相信 1 个 htaccess 中的 2 个不同的规则可以正确地适用于 2 个不同的文件。
两者均 100% 正常
工作
news
Link 2 显示的是 link1 的结果...,请告诉我为什么?
显示
消息
I'm not sure this [L] really works in each case to avoid overwrite one each other. I'm not an expert on this, but i spent a day to figure out that you just need to add 1 Atome to a RewriteRule that did worked before without beeing overwriten, and it starts to get overwriten again from the first one. It's hard for me to believe that 2 different Rules, in 1 htaccess can properly work for 2 differents files.
Both Worked 100% well
displ
news
Link 2 displays the result of link1 instead..., just tell me why?
displ
news