【问题标题】:htaccess add 301 moved permanently to RewriteRulehtaccess add 301 永久移动到 RewriteRule
【发布时间】:2011-05-03 20:11:18
【问题描述】:

我的 .htaccess 文件中有这条规则:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /index.php

它的作用是将所有 url 的 index.php?somevar=# 重定向到 index.php,但是当它重定向时发送代码 302,我希望它是 301。

我尝试在RewriteRule . /index.php 之后添加[R=301],但它不起作用。

感谢您的帮助:-)

【问题讨论】:

    标签: .htaccess mod-rewrite http-status-code-301


    【解决方案1】:

    这件事不符合你的描述。您的规则将对不存在文件的每个请求发送到index.php。网址:

    index.php?anything
    

    已经致电index.php。你不需要任何重写魔法来处理它。

    还有……

    重写规则。 /index.php
    

    是一种不好的做法。它现在不会给您带来问题,但将来您修改规则时可能会出现问题。你宁愿使用:

    RewriteRule .* /index.php
    

    【讨论】:

      猜你喜欢
      • 2019-11-04
      • 2012-07-10
      • 2013-09-26
      • 2019-10-14
      • 2018-06-18
      • 2018-06-23
      • 2021-08-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多