Htaccess文件不会更改文件扩展名

时间:2013-07-14 22:51:50

标签: html css html5 .htaccess xhtml

我想在我的网站上导航到另一个页面时删除我网站的结尾扩展名,但在修改我的.htaccess文件后,扩展程序仍在那里。

示例:

当前外观:website.com/index.html

我的需求:Website.com/index

内部文件:

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

1 个答案:

答案 0 :(得分:1)

下面我已经粘贴了手动切断扩展所需的网址重写代码,该代码应该位于您想要重写扩展名的网站目录中的.htaccess文件中。

RewriteEngine On
RewriteRule   horses.htm   Xu8JuefAtua.htm

这只会在地址栏中将horses.htm页面显示为Xu8JuefAtua.htm

要重写网址以不需要文件扩展名并且不区分大小写,那么这就是您要查找的代码:

RewriteEngine On
RewriteRule   ^horses/?$   Xu8JuefAtua.html  [NC]

正则表达式^表示URL路径的开头,?表示前面的字符,在这种情况下是不必要的斜杠。 $匹配网址的结尾。

Smashing Magazine在.htaccess文件上提供了很好的写作,以及如何使用正则表达式来执行各种操作,请查看their post