[英]web.config: redirect 301 doesn't work properly
我想对一个站点上的所有请求 (以及图像,文档和其他文件) 进行 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
但是我需要所有的重定向都在主页上。
我该怎么做?
您需要设置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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.