【问题标题】:My Website does not seem to like the removal of .html and I can't fix it我的网站似乎不喜欢删除 .html,我无法修复它
【发布时间】:2017-06-08 09:58:45
【问题描述】:

我已尝试使用 .htaccess 文件中的此代码删除网址末尾的 .html

RewriteEngine On
RewriteCond %{REQUEST_URI} !\.[a-zA-Z0-9]{3,4}
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.*)$ $1.html

但是正如您在转到my website 时所看到的那样,它只是重定向到没有.html 的链接并说禁止。我也有

Options -Indexes

在我的 .htaccess 文件中,但删除它并不能解决问题。

编辑:如果我将 .html 放在 url 的末尾,它可以工作,但如果我删除它,它会显示 Forbidden

请帮忙

谢谢

【问题讨论】:

标签: html .htaccess ubuntu


【解决方案1】:

试试这个:

RewriteEngine on

RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [NC,L]

这应该会从您的网址中删除.html。确保在测试之前清除缓存。

【讨论】:

  • 我这样做了,但我收到“由于可能的配置错误,请求超出了 10 个内部重定向的限制。如有必要,请使用 'LimitInternalRecursion' 增加限制。使用 'LogLevel debug' 获取回溯。”错误
【解决方案2】:

这应该适用于 apache:

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

我在自己的网站上也是这样做的(在 apache 上使用 .htaccess):

# Automatically redirect /index.html files to their URL directory
RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.html\ HTTP/
RewriteRule ^(.*)index\.html$ /$1 [R=301,L]

【讨论】:

  • 如果您访问 www.multicrew.co.uk/downloads.html,它会重定向到 /downloads/,表示未找到请求的 URL。
  • 没关系,我是个白痴,但是 .htaccess 文件编辑仍然对下载页面没有影响。
猜你喜欢
  • 2011-03-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多