故障去除html的URL扩展使用的.htaccess故障、html、htaccess、URL

2023-09-02 00:42:29 作者:酒虽伤胃、但不伤心

试图删除使用.htaccess中的网站HTML扩展。因此,例如:www.mysite.com/charts.html将成为www.mysite.com/charts

Trying to remove .html extensions from the site using .htaccess. So for example: www.mysite.com/charts.html would become www.mysite.com/charts

下面的脚本是在.htaccess文件中:

The following script is in the .htaccess file:

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

但是,当没有.html扩展名的URL输入到浏览器中,它显示了一个403 Forbidden错误。任何帮助将是AP preciated。

But when the url without the .html extension is entered in the browser, it shows a 403 Forbidden error. Any help would be appreciated.

推荐答案

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

I found this solution elsewhere:

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

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

sources: 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/

 
精彩推荐
图片推荐