Laravel .htaccess重写规则转换为IIS

Jav*_*diz 11 php iis iis-7 url-rewriting laravel

Laravel4框架附带了一个默认的.htaccess规则,用于创建漂亮的URL.

规则是这样的.

<IfModule mod_rewrite.c>
    Options -MultiViews
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)

问题:哪个在IIS中等效?

che*_*fly 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>
Run Code Online (Sandbox Code Playgroud)


小智 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>
Run Code Online (Sandbox Code Playgroud)