【问题标题】:Htaccess file does not change file extensionsHtaccess 文件不会更改文件扩展名
【发布时间】:2013-07-12 17:56:31
【问题描述】:

导航到我网站上的另一个页面时,我试图删除我网站的结尾扩展名,但修改我的 .htaccess 文件后扩展名仍然存在。

例子:

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

我想要它:Website.com/index

内部文件:

重写引擎开启 RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}.html -f 重写规则 ^(.*)$ $1.html

【问题讨论】:

  • 你的 htaccess 文件中有什么?
  • RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.html -f RewriteRule ^(.*)$ $1.html

标签: css html .htaccess xhtml


【解决方案1】:

下面我已经粘贴了手动切断扩展所需的 url 重写代码,它应该在您要为其重写扩展的网站目录中的 .htaccess 文件中。

RewriteEngine On
RewriteRule   horses.htm   Xu8JuefAtua.htm

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

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

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

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

Smashing Magazine 对 .htaccess 文件以及如何使用正则表达式进行各种操作进行了精彩的论述,请查看 their post

【讨论】:

    猜你喜欢
    • 2012-12-30
    • 1970-01-01
    • 2010-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-20
    • 2015-05-06
    • 1970-01-01
    相关资源
    最近更新 更多