【问题标题】:mod_rewrite redirects to .html in errormod_rewrite 错误地重定向到 .html
【发布时间】:2014-06-20 13:26:06
【问题描述】:

我刚刚在 OSX 10.9 上设置了一个 AMP 服务器,但遇到了一个奇怪的问题,该问题在我的实时托管服务器或旧 WAMP 服务器上不存在。

我想将任何不直接映射到服务器上文件的 URL 重定向到 index.php。我正在使用以下 .htaccess 代码

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# prevent loop
RewriteCond %{REQUEST_URI} !index\.php
RewriteRule ^(.*)$ /index.php?/$1 [L]

当我尝试http://example.com/example时没有问题,但是当我引入另一个斜线时,例如http://example.com/example/

我收到 404 错误 The requested URL /example.html/ was not found on this server.

服务器版本:Apache/2.2.26 (Unix)

【问题讨论】:

    标签: macos apache .htaccess mod-rewrite apache2


    【解决方案1】:

    看起来您的问题与在此处启用 MultiViews 有关。使用 .htaccess 顶部的这一行将其关闭:

    Options -MultiViews
    
    • 选项MultiViewsApache's content negotiation module 使用,它在mod_rewrite 之前运行,并使Apache 服务器匹配文件的扩展名。所以/file 可以在 URL 中,但它会服务于/file.php

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-23
      • 2016-03-27
      • 2021-03-12
      • 2012-05-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多