301 旧 Url 到新 Web.config
301 Old Url to New in Web.config
我正在尝试使用 web.config 在某些站点上将旧的 url 重定向到新的
我想准确地重定向 https://www.example.com/phone/ to https://www.example.com/all-phones-list
<rule name="Redirect to url" stopProcessing="true">
<add input="{HTTP_HOST}{REQUEST_URI}" pattern="example.com/phone/" />
<add input="{HTTP_HOST}{REQUEST_URI}" pattern="www.example.com/phone/" />
<action type="Redirect" url="https://www.example/all-phones-list" redirectType="Permanent"/>
</rule>
上面的代码有效,但挑战在于,像 https://www.example.com/phone/infinix-note-5/ also redirect to https://www.example.com/all-phones-list
这样的链接
请问我做错了什么?
您需要更新模式以使用“$”检查结尾,否则它也会匹配任何更长的字符串:
<add input="{HTTP_HOST}{REQUEST_URI}" pattern="example.com/phone/$" />
我正在尝试使用 web.config 在某些站点上将旧的 url 重定向到新的 我想准确地重定向 https://www.example.com/phone/ to https://www.example.com/all-phones-list
<rule name="Redirect to url" stopProcessing="true">
<add input="{HTTP_HOST}{REQUEST_URI}" pattern="example.com/phone/" />
<add input="{HTTP_HOST}{REQUEST_URI}" pattern="www.example.com/phone/" />
<action type="Redirect" url="https://www.example/all-phones-list" redirectType="Permanent"/>
</rule>
上面的代码有效,但挑战在于,像 https://www.example.com/phone/infinix-note-5/ also redirect to https://www.example.com/all-phones-list
这样的链接请问我做错了什么?
您需要更新模式以使用“$”检查结尾,否则它也会匹配任何更长的字符串:
<add input="{HTTP_HOST}{REQUEST_URI}" pattern="example.com/phone/$" />