我怎样才能避免在ASP.NET MVC中重复的内容,由于不区分大小写的URL和默认值? [英] How can I avoid duplicate content in ASP.NET MVC due to case-insensitive URLs and defaults?

查看:387
本文介绍了我怎样才能避免在ASP.NET MVC中重复的内容,由于不区分大小写的URL和默认值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

修改:现在我需要解决这个问题真的,我做多一点
  调查并想出了一个
  事情要减少重复号
  内容。我张贴详细的code
  减少:在我的博客样本
  重复的内容与ASP.NET MVC

Edit: Now I need to solve this problem for real, I did a little more investigation and came up with a number of things to reduce duplicate content. I posted detailed code samples on my blog: Reducing Duplicate Content with ASP.NET MVC

第一篇文章 - 去容易,如果我这个标错了标签或者是很糟糕:P

First post - go easy if I've marked this up wrong or tagged it badly :P

在微软的新ASP.NET MVC框架似乎有两件事情,可能会导致您的内容在多个网址(东西谷歌惩罚并会导致您的PageRank被碰到他们分开)送达了起来:

In Microsoft's new ASP.NET MVC framework it seems there are two things that could cause your content to be served up at multiple URLs (something which Google penalize for and will cause your PageRank to be split across them):


  • 不区分大小写的网址

  • 默认网址

您可以设置默认的控制器/动作以服务为请求域的根。比方说,我们选择的HomeController /索引。我们最终服务了相同的内容下列URL:

You can set the default controller/action to serve up for requests to the root of your domain. Let's say we choose HomeController/Index. We end up with the following URLs serving up the same content:


  • mydomain.com /

  • mydomain.com/Home/Index

现在如果人们开始链接到这两种然后将PageRank的分裂。谷歌也将考虑重复的内容和惩罚他们中的一个,以避免他们的结果重复。

Now if people start linking to both of these then PageRank would be split. Google would also consider it duplicate content and penalize one of them to avoid duplicates in their results.

在此之上,网址不区分大小写的,所以我们实际上得到这些网址的内容相同太:

On top of this, the URLs are not case sensitive, so we actually get the same content for these URLs too:


  • mydomain.com/Home/Index

  • mydomain.com/home/index

  • mydomain.com/Home/index

  • mydomain.com/home/Index

  • (不胜枚举)

所以,问题...我如何避免这些惩罚?我想:

So, the question... How do I avoid these penalties? I would like:


  • 进行默认操作的所有请求被重定向(301状态),以同样的网址

  • 所有URL区分大小写

可能?

推荐答案

除了张贴在这里,我通过电子邮件发送到ScottGu看他是否有一个良好的反响。他给了一个​​样品添加约束路线,所以你可以只响应小写网址:

As well as posting here, I emailed ScottGu to see if he had a good response. He gave a sample for adding constraints to routes, so you could only respond to lowercase urls:

public class LowercaseConstraint : IRouteConstraint
{
    public bool Match(HttpContextBase httpContext, Route route,
            string parameterName, RouteValueDictionary values,
            RouteDirection routeDirection)
    {
        string value = (string)values[parameterName];

        return Equals(value, value.ToLower());
    }

和寄存器路线方法:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapRoute(
        "Default",                                              // Route name
        "{controller}/{action}/{id}",                           // URL with parameters
        new { controller = "home", action = "index", id = "" },
        new { controller = new LowercaseConstraint(), action = new LowercaseConstraint() }
    );
}

这是一个开始,但倒是希望能够链接生成从像Html.ActionLink和RedirectToAction方法来匹配更改。

It's a start, but 'd want to be able to change the generation of links from methods like Html.ActionLink and RedirectToAction to match.

这篇关于我怎样才能避免在ASP.NET MVC中重复的内容,由于不区分大小写的URL和默认值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆