将http到https的重定向规则与“合并”;模式“U重写”;在IIS中?

将http到https的重定向规则与“合并”;模式“U重写”;在IIS中?,iis,Iis,我们如何将这两个IIS规则结合起来 “mod_rewrite”-将所有对PHP脚本的请求重定向到index.PHP 第二个是从http到https的经典重定向 但问题是,要么一个有效,要么另一个有效,这两个规则不能一起工作,告诉我如何将它们结合起来 <?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> &

我们如何将这两个IIS规则结合起来

  • “mod_rewrite”-将所有对PHP脚本的请求重定向到index.PHP
  • 第二个是从http到https的经典重定向
  • 但问题是,要么一个有效,要么另一个有效,这两个规则不能一起工作,告诉我如何将它们结合起来

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <system.webServer>
            <defaultDocument>
                <files>
                    <clear />
                    <add value="index.php" />
                </files>
            </defaultDocument>
            <rewrite>
                <rules>
                    <rule name="Silex Front Controller" enabled="true" 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" appendQueryString="true" />
                    </rule>
                    <rule name="http-to-https" stopProcessing="true">
                        <match url="(.*)" />
                        <conditions>
                            <add input="{HTTPS}" pattern="^OFF$" />
                        </conditions>
                        <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Found" />
                    </rule>
                </rules>
            </rewrite>
        </system.webServer>
    </configuration>
    

    您可以同时实现这两个规则。您只需要更改规则的顺序。首先放置https重定向规则:

    <rule name="http-to-https" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                        <add input="{HTTPS}" pattern="^OFF$" />
                    </conditions>
                    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Found" />
                </rule>
                <rule name="Silex Front Controller" enabled="true" stopProcessing="true">
                    <match url="^(.*)$" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php" appendQueryString="true" />
                </rule>