【问题标题】:IIS rewrite module canonical URL with two domains具有两个域的 IIS 重写模块规范 URL
【发布时间】:2017-08-05 10:04:26
【问题描述】:

我有一个网络服务器,我有两个名为 http://example.mxhttp://example.com.mx 的域都指向同一个网络服务器和根文件夹,我可以将我的网站与两个域一起使用,目前我可以使用 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 而我不想要这个,我需要在模式中更改什么?

【问题讨论】:

    标签: url redirect iis url-rewriting windows-server-2012


    【解决方案1】:

    你应该使用这个规则:

    <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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-14
      • 2016-04-25
      • 2020-10-24
      • 2014-02-02
      • 2010-10-17
      • 2012-11-05
      • 1970-01-01
      • 2011-12-04
      相关资源
      最近更新 更多