4

尝试使用 .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 错误。任何帮助,将不胜感激。

4

1 回答 1

8

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

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 /删除-文件-扩展-通过-htaccess/

于 2012-05-20T20:08:01.420 回答