【问题标题】:redirect rule not executed重定向规则未执行
【发布时间】:2012-10-02 07:13:10
【问题描述】:

我用 rubular.com 测试了以下重定向规则

^tags\/([a-zA-Z0-9_-]+)\.html

并以/tags/a-led.html 为例返回/tags/a-led。到目前为止,一切看起来都很好,但是当我在我的 htaccess 中应用规则时,如下所示

 RewriteRule ^tags\/([a-zA-Z0-9_-]+)\.html$  /tags/$1 [R,L]

还有一些其他的规则在后面

RewriteRule ^(.*)/(d*)-(.*)\.html$  /showthread.php?$1 [R,L]
RewriteRule ^(d*)-(.*)\.html$ /threads/$2 [R,L]

没有被执行,不幸的是我没有胶水可能是什么原因。

【问题讨论】:

  • 你打开重写引擎了吗??
  • 是已开启。我还有其他几条规则
  • 很明显,当您转到http://yourdomain.com/tags/a-led.html 时,您不会 被重定向(如浏览器地址栏中的URL 更改)到http://yourdomain.com/tags/a-led?但是其他重定向有效吗?
  • 不,我的其他重定向似乎没有问题

标签: regex .htaccess redirect rule


【解决方案1】:
  1. 该规则看起来不错,当我将它放在一个默认安装 apache 的空白 htaccess 文件中时它可以工作。
  2. 确保您已加载 mod_rewrite 并且您已打开重写引擎 (RewriteEngine On)。
  3. 如果您有其他规则,请确保您的重定向规则位于执行内部重写或路由的规则之前。
  4. 确保您的 htaccess 文件已被读取。您需要在服务器/虚拟主机配置中为 AllowOverride 设置正确的设置。设置 AllowOverride All 将确保 htaccess 文件中的所有内容都得到应用。

【讨论】:

    【解决方案2】:
    RewriteEngine On 
    RewriteRule ^tags\/([a-zA-Z0-9_-]+)\.html$  /tags/$1 [R,L]
    

    还可以使用 [R,L] 检查您是否在此之前设置了任何其他规则。 L 告诉 apache 如果这条规则匹配,则不要再处理任何规则。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-11-15
      • 1970-01-01
      • 2021-03-17
      • 1970-01-01
      • 2012-08-27
      • 1970-01-01
      • 2012-01-09
      相关资源
      最近更新 更多