[英].Net Url Rewrite to another domain with a specific path pattern
我正在开发一个新站点来替换我的旧站点,我的目的是将一些旧站点链接重定向到备份服务器(我将旧站点保留一段时间,直到找出所有网址路由)
例如,这是一些旧链接https://www.example.com/category/something/here
我希望新网站将上述网址重定向到https://backup.example.com/category/something/here
我不擅长Regex,我尝试过类似的方法,但是没有用,有什么想法吗? ks
<rule name="Redirect URL" stopProcessing="true">
<match url="^(.*)/category/(.*)" ignoreCase="true" />
<action type="Redirect" url="http://backup.example.com/{R:0}" redirectType="Permanent" />
</rule>
url
只能匹配路径。 要匹配实际的主机名,您需要使用{HTTP_HOST}
。
<?xml version="1.0"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect www.example.com or example.com to backup.example.com" stopProcessing="true">
<match url="^category/(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(www\.)?example.com$" />
</conditions>
<action type="Redirect" url="http://backup.example.com/category/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
<httpProtocol>
<redirectHeaders>
<!-- This is to ensure that clients don't cache the 301 itself - this is dangerous because the 301 can't change when put in place once it is cached -->
<add name="Cache-Control" value="no-cache"/>
</redirectHeaders>
</httpProtocol>
</system.webServer>
</configuration>
我还举了一个示例,说明如何关闭301重定向的缓存。 这可能会导致调试过程中出现问题,因为浏览器将缓存301重定向本身,然后忽略对该配置所做的任何更改,除非手动清除了缓存。
参考文献:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.