[英]web.config: redirect 301 doesn't work properly
I want to do a 301 redirect for all the requests on one site (also images, documents, and other files) to the homepage of another site . 我想对一个站点上的所有请求 (以及图像,文档和其他文件) 进行 301重定向, 将其重定向到另一站点的主页 。
I tried putting the web.config on the root of the site, and I'd insert this code: 我尝试将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>
But with this code on the web.config the problem is that if I digit: http://www.oldsite.com/file.html 但是在web.config上使用此代码时,问题是如果我输入以下内容: http : //www.oldsite.com/file.html
The browser redirect me to: http://www.newsite.com/file.html 浏览器将我重定向到: http : //www.newsite.com/file.html
But I need that all the redirects are on the homepage. 但是我需要所有的重定向都在主页上。
How can I do it? 我该怎么做?
You need to set exactDestination="true"
to make the destination absolute: 您需要设置
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>
See: https://www.iis.net/configreference/system.webserver/httpredirect 请参阅: https : //www.iis.net/configreference/system.webserver/httpredirect
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.