【问题标题】:Trouble removing .html URL extension using .htaccess使用 .htaccess 删除 .html URL 扩展时出现问题
【发布时间】:2012-05-27 10:33:18
【问题描述】:

尝试使用 .htaccess 从网站中删除 .html 扩展名。例如:www.mysite.com/charts.html 将变为 www.mysite.com/charts

以下脚本位于 .htaccess 文件中:

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

但是当在浏览器中输入不带.html扩展名的url时,会显示403 Forbidden错误。任何帮助将不胜感激。

【问题讨论】:

  • 我们必须创建一个conf文件吗?环顾四周,在我们的服务器文件中的任何地方都没有看到 conf 文件。

标签: html .htaccess url


【解决方案1】:

我在其他地方找到了这个解决方案:

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

来源: 1)http://www.catswhocode.com/blog/10-useful-htaccess-snippets-to-have-in-your-toolbox 2)http://eisabainyo.net/weblog/2007/08/19/removing-file-extension-via-htaccess/

【讨论】:

  • 我已经尝试了他们在该网站上的所有不同脚本,但似乎都不起作用,并且不断出现 403 错误。
  • 在删除具有相同 html 文件名的文件夹后,可以使用此脚本。谢谢。
  • 工作。谢谢!
猜你喜欢
  • 2015-06-20
  • 2015-12-27
  • 2016-12-28
  • 2014-03-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多