修改htaccess以删除url中的html扩展时出现错误505



我已经尝试了所有的教程和指南来删除静态html网站(mysite.com/page.html到mysite.com/page(上的html扩展,但除了错误什么都没有。

我总是这样:

错误500-内部服务器错误处理您的请求时遇到错误。通常情况下,这是一种临时情况。请联系网站所有者以获得进一步帮助

以下是我的根目录中的内容。htaccess当前:

RewriteEngine on
RewriteCond %{THE_REQUEST} /([^.]+).html [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.html  [NC,L]

我该怎么做才能让它正常工作?

对于您显示的示例,您可以尝试以下操作吗。请在测试URL之前清除浏览器缓存。

RewriteEngine on
##Putting one more condition here to make sure it runs only when called from external browser, to avoid possible loop.
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{THE_REQUEST} /([^.]+).html [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)/?$ $1.html  [NC,L]

最新更新