zoukankan      html  css  js  c++  java
  • URL重写

    什么是url重写:其实就是把url地址改了一下,

    对什么样的URL地址重写:带参数的url进行重写

    为什么对其重写:提高SEO优化,搜索引擎蜘蛛会根据url进行搜索,当爬到带参数的url时会把这个url的权重降低,因为参数会变,页面内容会变,所以要把带参数的url变成不带参数的url,其实并不是html权重高,只要不带参数,html,aspx权重一样高

    例子:

    aspx.cs

    重写前:

           node.NavigateUrl = ListBook.aspx?categoryId=" + item.Id;

    重写后

    node.NavigateUrl = "/ListBook/ListBook_" + item.Id + ".aspx";

    我们只要在请求管道的第一个事件里重写这个url就行了,因为只要是动态页面都会走请求管道的第一个事件,所以可以建一个Golble

    然后在global文件的 Application_BeginRequest的事件里处理请求,因为这个是管道的第一个事件

    在Application_BeginRequest里获取请求的url,

    string url = Request.AppRelativeCurrentExecutionFilePath;//获取的是~/book_1.aspx

    判断请求的url是否需要重写(用正则表达式),如果匹配成功进行重写:

             Match match= Regex.Match(url, @"~/BookList_(\d+).aspx");
             if (match.Success)
             {
                 string categoryId = match.Groups[1].Value;//获得类别编号
                 Context.RewritePath("/BookList.aspx?categoryId=" + categoryId);//重写url
             }

    Application_BeginRequest代码:

     protected void Application_BeginRequest(object sender, EventArgs e)
            {
              string url =Request.AppRelativeCurrentExecutionFilePath;//~/BookList_26.aspx
                //判断用户请求的url是否是需要重写。
             Match match= Regex.Match(url, @"~/BookList_(\d+).aspx");
             if (match.Success)
             {
                 string categoryId = match.Groups[1].Value;
                 Context.RewritePath("/BookList.aspx?categoryId=" + categoryId);
             }
    
            }
  • 相关阅读:
    20160130.CCPP体系详解(0009天)
    20160129.CCPP体系详解(0008天)
    20160128.CCPP体系详解(0007天)
    20160127.CCPP体系详解(0006天)
    20160126.CCPP体系详解(0005天)
    程序员_你的“强迫症”有哪些?
    天天写业务代码_如何成为技术大牛?
    阿里云全球首批MVP李文毅专访-一个“改邪归正”的90后
    【毕业季】穿越回毕业前一年_这次你会怎么选
    恢复Hyper-V虚拟机丢失的数据文件过程
  • 原文地址:https://www.cnblogs.com/guohuiru/p/3056371.html
Copyright © 2011-2022 走看看