使用.htaccess删除文件扩展名:以斜杠结尾的错误 [英] Remove file extension with .htaccess: Error with trailing slash

查看:143
本文介绍了使用.htaccess删除文件扩展名:以斜杠结尾的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用.htaccess从我的网站中删除像.html这样的文件扩展名。最终结构应如下所示:

  http://domain.com/file-> http://domain.com/file.html 
http://domain.com/file/ - > http://domain.com/file.html

使用.htaccess中的现有代码,我会当末尾有斜线时,在我的浏览器中出现内部服务器错误。我能做什么?

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


解决方案

  RewriteEngine On 
RewriteBase /
RewriteRule ^([a-zA-Z0-9 -_] +)/?$ $ 1。 html [L]


I want to remove the file extension like .html from my websites with .htaccess. The final structure should be like so:

http://domain.com/file  --> http://domain.com/file.html
http://domain.com/file/ --> http://domain.com/file.html

With my existing code in .htaccess I'll get "Internal Server Error" on my Browser when there's a trailing slash at the end. What can I do? Thanks!

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

解决方案

RewriteEngine On
RewriteBase /
RewriteRule ^([a-zA-Z0-9-_]+)/?$ $1.html [L]

这篇关于使用.htaccess删除文件扩展名:以斜杠结尾的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆