11

Laravel4 框架带有一个默认的 .htaccess 规则来创建漂亮的 url。

规则是这样的。

<IfModule mod_rewrite.c>
    Options -MultiViews
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

问题: IIS 中的等价物是什么?

4

3 回答 3

8

您可以使用导入 Apache 规则功能将 Apache 规则转换为 IIS。

在您的情况下,它将如下所示:

进口

或者在web.config文件中:

<rule name="Imported Rule 1" stopProcessing="true">
    <match url="^" ignoreCase="false" />
    <conditions logicalGrouping="MatchAll">
        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
    </conditions>
    <action type="Rewrite" url="index.php" />
</rule>
于 2013-02-22T15:34:51.993 回答
5

感谢 Oli Folkerd,这对我有用:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Laravel4" stopProcessing="true">
                    <match url="^" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php" appendQueryString="true" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>
于 2014-11-29T20:31:29.097 回答
2

有几个额外的部分值得放在您的 web.config 文件中

下面的代码允许您使用附加的 PUT 和 DELETE HTTP 动词创建 restfull 控制器,并允许在远程调试服务器时显示 laravel 的自定义错误页面:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Laravel4" stopProcessing="true">
                    <match url="^" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php" appendQueryString="true" />
                </rule>
            </rules>
        </rewrite>
        <handlers>
            <remove name="PHP53_via_FastCGI" />
            <add name="PHP53_via_FastCGI" path="*.php" verb="GET,HEAD,POST,PUT,DELETE" modules="FastCgiModule" scriptProcessor="C:\Program Files (x86)\PHP\v5.3\php-cgi.exe" resourceType="Either" requireAccess="Script" />
        </handlers>
        <httpErrors errorMode="Detailed" />
    </system.webServer>
</configuration>
于 2014-05-01T11:46:27.130 回答