【问题标题】:I can't remove .html, extension我无法删除 .html,扩展名
【发布时间】:2015-09-08 19:37:14
【问题描述】:

您好,我一直在寻找一种摆脱.html 扩展名的方法,他们都说要创建一个.htaccess 文件,我已经完成并将代码放入文件中,但它仍然不起作用。我不确定我保存在正确的区域还是输入了错误的代码。

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]

【问题讨论】:

  • 你应该检查你的服务器配置。您的 mod_rewrite dll 可能已禁用。你需要启用它。像 apache 服务器一样,您可以在 httpd.conf 中检查

标签: php html css .htaccess


【解决方案1】:

试试这个

<IfModule mod_rewrite.c>
   RewriteEngine On
   RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /html/(.*).html\ HTTP/
   RewriteRule .* http://localhost/html/%1 [R=301,L]

   RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /html/(.*)\ HTTP/
   RewriteRule .* %1.html [L]
</IfModule>

希望对你有帮助。

【讨论】:

  • 感谢您的回复,我该把这段代码放在哪里?
  • 所以我将所有代码放在我的 .htaccess 文件中。我不确定我保存在正确的区域,我正在使用 Brackets 软件创建我的网站,只是将 .htaccess 文件保存在我的网站文件中,对吗?
  • .htaccess 文件通常位于项目的根目录中。
  • 真的很抱歉,我是初学者,你能解释一下项目的根源吗?
  • @user3660857 这意味着如果您的服务器的根目录是 public_html,那么您将它放在那里。对于某些人来说,它可能是 httpdocs,并且可能因系统而异。
猜你喜欢
  • 2020-07-20
  • 2017-05-08
  • 2015-03-20
  • 2022-03-04
  • 1970-01-01
  • 1970-01-01
  • 2019-04-21
  • 2013-01-09
  • 2017-05-05
相关资源
最近更新 更多