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);
             }
    
            }
  • 相关阅读:
    Mybatis入门环境搭建
    sts,eclipse里面配置tomcat
    IDEA-导入本地所需要的jar包
    Java使用poi生成Excel,生成两种表格下拉框
    Java使用poi生成Excel表格
    Java synchronized(this)锁住的是什么
    Java多线程之使用ATM与柜台对同一账户取钱
    Java多线程对同一个对象进行操作
    Java Socket通信实例
    java基本数据类型和引用数据类型的区别
  • 原文地址:https://www.cnblogs.com/guohuiru/p/3056371.html
Copyright © 2011-2022 走看看