IIS 10/Apache Issues - web.config



我在使用目录/变量规则方面遇到了问题,这些规则可以在各种语言中看到。例如:

http://example.com/foo/bar

应读取为example.com,并将foo和bar作为变量。

然而,在IIS中,无论我做了多少重写,它似乎都无法识别这一点

<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>

公用文件夹中转换/对应的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,因为目录不存在(它不存在,因此重写(。

有什么想法吗?

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

像这样的东西:

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

最新更新