问题原文
原帖链接 · user1780087 · CC BY-SA 4.0
I have several domains sharing the same site and use a default.asp as the default file where I test the SERVER_NAME variable and use Response.Redirect to redirect to the home page of the site requested.
The problem is that this type of redirect causes 302 status code. Even when having a rewrite section in my web.config where I created one redirect rule for each site with redirectType="Permanent", the status code 302 is returned.
That is bad for ranking pages in Google's index. Does somebody know a way to solve that problem and return 301 status code?
已采纳解答
原帖链接 · Trebor · CC BY-SA 4.0
I'm assuming you're using classic ASP (not .NET) since you refer to default.asp and not default.aspx.
Instead of using response.redirect and counting on your web config file to change from a 302 to a 301, try adding the 301 to the response object before redirecting the user.
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", "new_page_name.asp"
%>
If you're actually using .NET, then use the following:
<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location","http://example.com");
}
</script>
See https://docs.microsoft.com/en-us/previous-versions/iis/6.0-sdk/ms525844(v=vs.90) for more information.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
