【问题标题】:Website links won't work with .htaccess code which removes .html extension网站链接不适用于删除 .html 扩展名的 .htaccess 代码
【发布时间】:2018-03-04 14:49:04
【问题描述】:

我的 .htacess 文件中有以下代码,用于我的网站从我的网址中删除“.html”并将任何 .html 重定向到没有它的同一页面(example.com/home.html 到 example.com/家)

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ /$1 [L,R=301] 

#301 from example.com/page.html to example.com/page
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.html\ HTTP/
RewriteRule ^(.*)\.html$ /$1 [R=301,L]

但是,当我尝试点击指向我网站上其他页面的链接时,我收到 404 错误。 我尝试将 href 设置为 http://www.example.com/page2、/page2 等,但我仍然遇到同样的错误。有什么帮助吗?

【问题讨论】:

    标签: html .htaccess web


    【解决方案1】:

    请保存您的代码并仅将以下代码放在您的主目录.htaccess 文件中:

      RewriteEngine on
      RewriteCond %{THE_REQUEST} \s/+(.*?/)?(.*?)\.html[\s?/] [NC]
      RewriteRule  (.*)$  /%1%2 [R=302,L,NE]
    

    注意:清除浏览器缓存,因为您执行了301 重定向并测试代码

    【讨论】:

    • 我改了,它什么也没做
    • 是的,我做到了。还是什么都没做。我可以访问主域上的多个页面,但无法访问辅助域上的任何页面
    • 它对我来说很好用,你有另一个浏览器对吗?如果您通过 chrome 使用 IE 进行检查,我的意思是更改浏览器,
    猜你喜欢
    • 1970-01-01
    • 2013-04-10
    • 1970-01-01
    • 2018-08-21
    • 2016-12-28
    • 2014-03-04
    • 2015-06-20
    • 1970-01-01
    相关资源
    最近更新 更多