如何在IIS上配置web.config以发布YII2 Advanced

如何在IIS上配置web.config以发布YII2 Advanced,yii2,iis-7,web-config,yii2-advanced-app,Yii2,Iis 7,Web Config,Yii2 Advanced App,我正在安装一个基于YII2高级主题的应用程序。它在Apache上运行得很好,但是在IIS 7上安装时,漂亮的URL会非常糟糕,我使用以下web.config <?xml version="1.0" encoding="UTF-8"?> <configuration> <configSections> <sectionGroup name="system.webServer"> <sectionG

我正在安装一个基于YII2高级主题的应用程序。它在Apache上运行得很好,但是在IIS 7上安装时,漂亮的URL会非常糟糕,我使用以下web.config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <configSections>
        <sectionGroup name="system.webServer">
            <sectionGroup name="rewrite">
                <section name="rewriteMaps" overrideModeDefault="Allow" />
                <section name="rules" overrideModeDefault="Allow" />
            </sectionGroup>
        </sectionGroup>
    </configSections>

    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Imported Rule 1" stopProcessing="true">
                    <match url="^(.*)$" ignoreCase="false" />
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

任何可以帮助我解决这个问题的想法。

经过几天的搜索,试图理解dos为什么不工作。我运气不太好

最后我找到了

第一:
确保已在IIS7上安装URL重写

如果您有web.config配置,并且它仍然路由到物理目录,而不是控制器/操作路由,则几乎100%意味着您缺少
URL Rewrite
。是的,这是一个不一定安装的插件

所以,继续吧,从你的ISS上下载并安装它

秒:
这是实际工作的web.config。请注意,我的结尾是:
match url=“.*”
,还请注意,我添加了一行来处理图像和其他静态内容

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <configSections>
        <sectionGroup name="system.webServer">
            <sectionGroup name="rewrite">
                <section name="rewriteMaps" overrideModeDefault="Allow" />
                <section name="rules" overrideModeDefault="Allow" />
            </sectionGroup>
        </sectionGroup>
    </configSections>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Yii2 Routing that works" stopProcessing="true">
                    <match url=".*" />
                    <conditions  logicalGrouping="MatchAll" trackAllCaptures="false">
                        <add input="{REQUEST_FILENAME}" pattern="css|js|jpg|jpeg|png|gif|ico|htm|html" negate="true" />                            
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

我仍在调试并试图解决一些小问题,如果发现其他问题,我将更新操作系统。

可能重复@lex li close,答案可能表明它是重复的。我不确定。但是,他们的答案仍然不能回答这里的问题。如何在web.config上进行正确的配置?还在和它战斗。答案让我有点困惑,他们指向另一个关于数据库的问题。我想这个问题很清楚,引用的副本不是。这里的问题是如何配置web.config,以便它将控制器/操作路由到index.php?r=Please@lex li中的点,如果您认为我错了,请告诉我,以及该怎么做。
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <configSections>
        <sectionGroup name="system.webServer">
            <sectionGroup name="rewrite">
                <section name="rewriteMaps" overrideModeDefault="Allow" />
                <section name="rules" overrideModeDefault="Allow" />
            </sectionGroup>
        </sectionGroup>
    </configSections>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Yii2 Routing that works" stopProcessing="true">
                    <match url=".*" />
                    <conditions  logicalGrouping="MatchAll" trackAllCaptures="false">
                        <add input="{REQUEST_FILENAME}" pattern="css|js|jpg|jpeg|png|gif|ico|htm|html" negate="true" />                            
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>
'urlManager' => [
   'enablePrettyUrl' => true,
   'showScriptName' => false,
...
]