【问题标题】:IIS 10/Apache Issues - web.configIIS 10/Apache 问题 - web.config
【发布时间】:2020-11-07 10:54:07
【问题描述】:

我在使用可以在各种语言中看到的目录/变量规则时遇到问题。 例如:

http://example.com/foo/bar

应该读作 example.com,其中 foo 和 bar 作为变量。

但是在 IIS 中,无论我进行多少重写,它似乎都无法识别这一点。这是有效的 apache .htaccess 文件:

<IfModule mod_rewrite.c>
    Options -Multiviews
    RewriteEngine Options
    RewriteBase /richie/public
    RewriteCond %{REQUEST_FILENAME} "-d
    RewriteCond %{REQUEST_FILENAME} "-f
    RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
</IfModule>

public文件夹中转换/对应的IIS web.config文件如下:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Rule1" stopProcessing="true">
          <match url="^(.*)$" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          </conditions>
          <action type="Rewrite" url="index.php?url={R:1}" appendQueryString="true" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

但是 IIS 似乎忽略了它......我只是得到 404,因为目录不存在(它不存在,因此重写)。

有什么想法吗?

【问题讨论】:

标签: apache iis


【解决方案1】:

当您在重写的 URL 中指定唯一的文件名而没有路径和主机名时,它将尝试在您应用规则的特定目录中查找 URL。在您的情况下,它试图在公用文件夹中查找 index.php 文件,但它不可用,因此您收到 404 错误而不是索引页面。所以只需尝试在重写 URL 的索引页面中添加主机名:

类似这样的:

http://www.example.com/index.php?url={R:1}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-08
    • 2016-11-03
    • 2012-11-01
    • 2017-02-15
    • 2012-01-30
    • 1970-01-01
    相关资源
    最近更新 更多