我想对一个网站上的所有请求(也包括图片,文档和其他文件)进行301重定向到另一个网站的主页。
我尝试将web.config放在网站的根目录上,然后插入此代码:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location>
<system.webServer>
<httpErrors existingResponse="PassThrough" />
<httpRedirect enabled="true" destination="http://www.newsite.com/" httpResponseStatus="Permanent" />
</system.webServer>
</location>
</configuration>
但是在web.config上有这个代码,问题是如果我数字: http://www.oldsite.com/file.html
浏览器会将我重定向到:http://www.newsite.com/file.html
但我需要所有重定向都在主页上。
我该怎么做?
答案 0 :(得分:0)
您需要设置exactDestination="true"
以使目标成为绝对目标:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location>
<system.webServer>
<httpErrors existingResponse="PassThrough" />
<httpRedirect exactDestination="true" enabled="true" destination="http://www.newsite.com/" httpResponseStatus="Permanent" />
</system.webServer>
</location>
</configuration>
请参阅:https://www.iis.net/configreference/system.webserver/httpredirect