【问题标题】:WAMP - Trailing Slash (/) Gives Error 500 "Internal Server Error" - .htaccess Error?WAMP - 尾部斜杠 (/) 给出错误 500“内部服务器错误” - .htaccess 错误?
【发布时间】:2012-10-06 21:37:26
【问题描述】:

我在我的计算机上使用 WAMP,在编写我的网站时,我决定删除 .html 扩展名,以期改善美观。

这很好用,所以,就我而言,temp.jakegriffin.co.uk/index.html 变成了 /index,这正是我想要的。不幸的是,如果有一个尾随 / 后索引,我得到:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete     your request.

Please contact the server administrator, admin@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

当我尝试在 .htaccess 文件中修复此问题时,我会收到错误 403(我被禁止)或错误 404(网页不存在)。

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

这是我的 .htaccess 文件中用于删除扩展名的代码。如果有人可以帮助我,将不胜感激。

提前致谢, 杰克。

【问题讨论】:

  • apache 错误日志说什么......?

标签: .htaccess wamp


【解决方案1】:

这个 mod_rewrite 规则:

 * http://planetozh.com/blog/2004/05/apache-and-the-trailing-slash-problem/

    RewriteEngine  on
    RewriteBase    /
    RewriteCond    %{REQUEST_FILENAME}  -d
    RewriteRule    ^(.+[^/])$ $1/

【讨论】:

【解决方案2】:

试试这个:

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

现在您可以在index 之后添加一堆正斜杠 (/) ;)

【讨论】:

  • 不,那没用。当没有斜杠时,它只会导致 404 错误。但是,当没有尾部斜杠时,它确实有效。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-08-09
  • 1970-01-01
  • 2015-02-15
  • 1970-01-01
  • 2021-09-28
  • 1970-01-01
相关资源
最近更新 更多