Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
具有两个域的IIS重写模块规范URL_Url_Redirect_Iis_Url Rewriting_Windows Server 2012 - Fatal编程技术网

具有两个域的IIS重写模块规范URL

具有两个域的IIS重写模块规范URL,url,redirect,iis,url-rewriting,windows-server-2012,Url,Redirect,Iis,Url Rewriting,Windows Server 2012,我有一个Web服务器,我有两个域名http://example.mx和http://example.com.mx两者都指向同一个Web服务器和根文件夹,我可以将我的网站与这两个域一起使用,目前我也可以使用www.,但这是我要删除的内容,我做到了,我得到了这个web.config文件 <?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <

我有一个Web服务器,我有两个域名
http://example.mx
http://example.com.mx
两者都指向同一个Web服务器和根文件夹,我可以将我的网站与这两个域一起使用,目前我也可以使用
www.
,但这是我要删除的内容,我做到了,我得到了这个web.config文件

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <handlers>
            <remove name="CGI-exe" />
            <add name="CGI-exe" path="*.exe" verb="*" modules="CgiModule" resourceType="File" requireAccess="Script" allowPathInfo="true" />
        </handlers>
        <rewrite>
            <rules>
                <rule name="CanonicalHostNameRule2" enabled="false">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTP_HOST}" pattern="^example\.com\.mx$" negate="true" />
                    </conditions>
                    <action type="Redirect" url="http://example.com.mx/{R:1}" />
                </rule>
                <rule name="CanonicalHostNameRule1" enabled="false">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTP_HOST}" pattern="^example\.mx$" negate="true" />
                    </conditions>
                    <action type="Redirect" url="http://example.mx/{R:1}" />
                </rule>
                <rule name="http a https" enabled="false" patternSyntax="ECMAScript" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTPS}" pattern="^OFF$" />
                    </conditions>
                    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

但问题是我去
http://example.mx
它将我发送到
http://example.com.mx
假设它的工作原理如下:

如果我转到
http://www.example.mx
重定向到
http://example.mx

如果我转到
http://www.example.com.mx
重定向到
http://example.com.mx


但是现在如果我去
http://www.example.mx
它重定向到
http://example.com.mx
我不想这样,我需要在模式中改变什么

您应该使用以下规则:

<rule name="CanonicalHostNameRule2">
    <match url="(.*)" />
    <conditions>
         <add input="{HTTP_HOST}" pattern="^www\.example\.com\.mx$"/>
    </conditions>
    <action type="Redirect" url="http://example.com.mx/{R:1}" />
</rule>
<rule name="CanonicalHostNameRule1">
    <match url="(.*)" />
    <conditions>
         <add input="{HTTP_HOST}" pattern="^www\.example\.mx$" />
    </conditions>
    <action type="Redirect" url="http://example.mx/{R:1}" />
</rule>