SEO:重复的 URL(带或不带破折号“/”)和 ASP.NET MVC
阅读本文“斜线或不斜线”后(链接:http://googlewebmastercentral.blogspot.com/2010/04/to-slash-or-not-to-slash.html) 在 Google 网站站长中心博客(官方博客)上 我决定测试一下我的 ASP.NET MVC 应用程序。
例如: http://domain.com/products 和 http://domain.com/products/(末尾带有“/”),返回代码 200,这意味着:Google 将其理解为两个不同的链接,并且可能成为“重复内容”。他们建议选择您想要的方式...带或不带破折号,并创建 301 永久重定向到首选方式。
因此,如果我选择不带破折号,当我尝试访问 http://domain.com/products/ 时将返回 301 到不带破折号的链接:http://domain.com/products。
问题是,如何使用 ASP.NET MVC 做到这一点?
谢谢, 桂
after reading this article "Slash or not to slash" (link: http://googlewebmastercentral.blogspot.com/2010/04/to-slash-or-not-to-slash.html) on Google Webmaster Central Blog (the oficial one) I decided to test my ASP.NET MVC app.
For example:
http://domain.com/products and http://domain.com/products/ (with "/" in the end), return the code 200, which means: Google understands it as two different links and likely to be a "duplicated content". They suggest to choose the way you want... with or without dash and create a 301 permanent redirect to the preferred way.
So if I choose without dash, when I try to access http://domain.com/products/ it will return a 301 to the link without dash: http://domain.com/products.
The question is, how can I do that with ASP.NET MVC?
Thanks,
Gui
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您使用 IIS 7,则可以使用 URL 重写扩展 ScottGu 有一篇关于它的博客文章 此处。
或者,如果您想在代码中执行此操作,您可以从 PerRequestTask 继承。这里有一些示例代码,从地址中删除 www - 这是来自 Shrinkr:
您只需要检查对于代码中以 / 结尾的 url。
** 请注意,这确实使用了第 3 方 dll - System.Web.MVC.Extensibility 命名空间。 **
If your using IIS 7 you could use the URL Rewrite Extension ScottGu has a blog post about it here.
Alternatively if you want to do it in code you could inherit from PerRequestTask. Here some sample code the removes the www from an address - this is from Shrinkr:
You would just need to check for the url ending with a / in your code.
** Note this does use a 3rd party dll - System.Web.MVC.Extensibility namespace. **
对于谷歌来说这并不重要,但重要的是两个网址是否
http://domain.com/products 和 http://domain.com/products/ 显示同一页面,您还需要使用链接到您网站的 Windows 服务器进行观看,例如从用户键入的外部页面http://domain.com/PRODUCTS/ 也将被视为与网络情况不同的页面敏感的。
通过使用规范的 url 元标记可以解决这个问题,它告诉 google 页面名称的真正含义,因此可以避免重复的页面,从而避免重复
http://googlewebmastercentral.blogspot.com/2009/02/specify-your-canonical.html
It dosnt matter really for Google, but what does matter is if both urls'
http://domain.com/products and http://domain.com/products/ show the same page, you also need to watch with windows servers that links to your site like from external pages where the user has typed http://domain.com/PRODUCTS/ will aloso be seen as a diffrent page as the web is case sensitive.
There is away round this with the use of canonical url meta tag, it tell s google what the page name is really, so will avoid duplicate pages which ant really diuplicate
http://googlewebmastercentral.blogspot.com/2009/02/specify-your-canonical.html
您需要检查 INIT 事件中的 URI,并检查 URI 是否带有斜杠,如果是,只需执行重定向并将 301 标头添加到输出响应中。
you need to check the URI in the INIT event and check the URI to see if it coming in with the slash, if it is, simply do a redirect and add the 301 header to the output response.