【问题标题】:What mod_rewrite rule will 301 redirect /example.html to /example?什么 mod_rewrite 规则将 301 重定向 /example.html 到 /example?
【发布时间】:2010-03-10 09:16:55
【问题描述】:

我想翻译或 301 重定向网址,例如:

www.domain.com/example.html 到 www.domain.com/example

以下是当前的重写规则:

   RewriteEngine On
   RewriteBase /
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.*)$ index.php/$1 [QSA,L]
   RewriteCond %{SERVER_PORT} 80 

【问题讨论】:

    标签: .htaccess mod-rewrite


    【解决方案1】:

    请尝试以下方法:

    RewriteRule ^(.+)\.html$ $1 [R=301,L]
    RewriteCond %{REQUEST_FILENAME}.html -f
    RewriteRule ^(.+)$ $1.html [L]
    

    【讨论】:

      【解决方案2】:

      试试RewriteRule (.+)\.html$ $1 [R=301]

      【讨论】:

      • 部分工作,谢谢。是否可以创建一个规则,导致最终重写就像 .html 不存在一样?它以不同的方式解释响应。也许我需要将其修改为更类似于包含 index.php 的这一行? RewriteRule ^(.*)$ index.php/$1 [QSA,L]
      • 嗯,我不确定你的意思。请给出一些示例输入和输出。
      猜你喜欢
      • 2011-03-23
      • 2021-04-10
      • 1970-01-01
      • 2013-01-21
      • 2010-12-22
      • 2011-01-05
      • 1970-01-01
      相关资源
      最近更新 更多