[英]IIS rewrite module canonical URL with two domains
我有一个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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.