【问题标题】:Getting a 404 with htaccess使用 htaccess 获取 404
【发布时间】:2014-11-28 09:29:35
【问题描述】:

我希望有人可以帮助我。

我的网站的公共 html 文件夹中有一个 htaccess 文件,其中包含以下内容:

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

所以当我访问我的网站 newsletter.html 时,它会重定向到 domain.co.uk/newsletter 而不是 domain.co.uk/newsletter.html 这正是我想要的.. 但我也得到一个 404 说页面无法显示。有问题的网页在我的文件管理器中被命名为 newletter.html。

有人知道为什么不能显示吗?

【问题讨论】:

    标签: html .htaccess mod-rewrite redirect


    【解决方案1】:

    要隐藏 .html 扩展,请在根 .htaccess 中使用此代码:

    RewriteEngine on
    
    RewriteCond %{THE_REQUEST} \s/+(.+?)\.html[\s?] [NC]
    RewriteRule ^ /%1 [R=302,L,NE]
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{DOCUMENT_ROOT}/$1\.html -f [NC]
    RewriteRule ^(.+?)/?$ /$1.html [L]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-19
      • 2011-07-22
      • 1970-01-01
      • 1970-01-01
      • 2017-08-07
      • 2018-04-21
      • 2017-10-10
      • 1970-01-01
      相关资源
      最近更新 更多