【问题标题】:.htaccess: remove .html and redirect slash version.htaccess:删除 .html 并重定向斜杠版本
【发布时间】:2017-04-21 23:25:27
【问题描述】:

在我的网站上,所有页面都具有 .html 扩展名,并且直接位于根目录下(即 site.com/page.html)。我已成功使用以下 .htaccess 代码使 .html 不显示:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]

这给了我一个类似 site.com/page 的网址,但如果用户使用斜杠链接或访问该网址(即 site.com/page/),我想 301 重定向到非斜线版本。

我无法将此部分集成到上述代码中。提前感谢您的任何建议。

【问题讨论】:

    标签: html .htaccess redirect mod-rewrite url-rewriting


    【解决方案1】:

    尝试这样的事情

     RewriteCond %{REQUEST_URI} !(.*)/$
     RewriteRule ^(.*)$ http://www.example.com/$1/ [L,R=301]
    

    【讨论】:

      猜你喜欢
      • 2012-07-01
      • 2019-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多