【问题标题】:Remove .html from url through .htaccess通过 .htaccess 从 url 中删除 .html
【发布时间】:2015-08-30 06:06:23
【问题描述】:

经过一些 apache 设置后,我在 Localhost 中使用以下代码,它工作正常。

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

但是当我在托管服务器上上传这个 .htaccess 文件时,显示错误 404。当我在线检查 .htaccess 测试仪时,它显示"This variable is not supported: %{REQUEST_FILENAME}"

【问题讨论】:

  • 这个 .htaccess 在托管服务器的什么位置?
  • 在根目录下除了Index.html文件。
  • 您是否启用了mod_rewrite
  • 你在运行 apache 吗?如果您正在运行另一台服务器,例如 lighttpd,它甚至不会查看 .htaccess。
  • 当我放入一些代码 .htaccess 文件时,它会在登录页面上显示错误 500。

标签: php html .htaccess


【解决方案1】:

这应该可行:

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

【讨论】:

    猜你喜欢
    • 2011-03-08
    • 2020-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-28
    • 2017-01-12
    相关资源
    最近更新 更多