【发布时间】:2011-12-19 20:59:13
【问题描述】:
我有一个 aspx 页面:1.aspx
我的应用程序和 rewriteurl 模块中没有任何路由。
我如何告诉谷歌:
我不再使用 1.aspx
请使用2.aspx instead
他的机器人总是在搜索 1.aspx
我该如何阻止它(并告诉他寻找 2.aspx 代替)?
【问题讨论】:
我有一个 aspx 页面:1.aspx
我的应用程序和 rewriteurl 模块中没有任何路由。
我如何告诉谷歌:
我不再使用 1.aspx
请使用2.aspx instead
他的机器人总是在搜索 1.aspx
我该如何阻止它(并告诉他寻找 2.aspx 代替)?
【问题讨论】:
使用robots.txt 文件:
您可以在应用程序的根目录下创建一个robots.txt 文件并将以下内容放入其中:
User-agent: Google
Disallow: 1.aspx
更多关于 robots.txt 文件http://www.robotstxt.org/robotstxt.html
进行重定向:
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location", "/2.aspx");
在Global.asax 中不存在该页面的情况下进行重定向:
void Application_BeginRequest(object sender, EventArgs e) {
string url = Request.Url.ToString().ToLower();
if (url.Contains("/1.aspx")) {
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location", "/2.aspx");
}
}
【讨论】:
Google 会自动刷新。从您的网站中删除 1.aspx 页面。然后机器人会寻找该文件一段时间,但会扫描其余文件并更新索引。
【讨论】:
使用 301 永久重定向。如果您使用的是 .NET
Response.Status = "301 Moved Permanently";
Response.StatusCode = 301;
Response.AddHeader("Location","http://www.new-url.com");
Response.End();
如果您使用的是 .NET 4.0:
Response.RedirectPermanent("http://www.new-url.com");
您可以了解有关 301 重定向的移动以及 Google 如何处理它们here。
【讨论】:
您将需要使用 301 重定向。
这取决于您的技术,但您可以通过http://www.webconfs.com/how-to-redirect-a-webpage.php了解更多信息
例如在 ASP 中
<%@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","http://www.new-url.com/"
%>
对于 ASP.NET
<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location","http://www.new-url.com");
}
</script>
您可以在此处阅读有关服务器端重定向的更多信息:
分别用于 Microsoft Internet Information Services 和 Apache。
【讨论】:
301 将 1.aspx 重定向到 2.aspx。
客户端重定向将强制您保留该页面。通过 IIS(或任何托管您的应用程序)进行的服务器端重定向将永久生成 1.aspx -> 2.aspx。你可以删除页面,没关系。
【讨论】: