【问题标题】:301 Redirect New Website URL Structure .htaccess301重定向新网站URL结构.htaccess
【发布时间】:2017-01-07 11:49:33
【问题描述】:

我的网站正在更改 URL,并将删除文件扩展名 .html

旧网址:

http://example.com/states.html 

新网址:

http://example.com/states

如何设置我的 .htaccess 文件以执行站点范围的重定向,删除 .html 扩展名?

【问题讨论】:

    标签: .htaccess redirect


    【解决方案1】:

    要从 .html 重定向到无扩展名的 URL,请在 .htaccess 文件顶部附近尝试以下操作(在重写“漂亮” URL 的前端控制器之前)。

    RewriteEngine On
    RewriteRule (.+)\.html$ /$1 [R=302,L]
    

    当您确定它工作正常时,将302(临时)重定向更改为301(永久)。 301 被浏览器缓存,因此如果出现错误可能会使测试出现问题。

    【讨论】:

      【解决方案2】:

      这应该对你有用:

      RewriteEngine on 
      RewriteCond %{REQUEST_FILENAME} !-d 
      RewriteCond %{REQUEST_FILENAME}\.html -f 
      RewriteRule ^(.*)$ $1.html
      

      【讨论】:

        猜你喜欢
        • 2012-03-23
        • 2013-01-07
        • 2013-08-01
        • 2017-02-04
        • 2012-12-17
        • 2023-03-02
        • 2017-09-21
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多