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);
             }
    
            }
  • 相关阅读:
    node项目发布pm2
    图片地址获取图片信息
    前端文件上传 获取文件大小 获取图片宽高
    前端上传图片预览
    vue按钮防暴力点击
    小程序父子组件之间的通信
    form表单
    es6-函数的扩展
    php的魔术常量以及类的模式方法
    OpenStack笔记
  • 原文地址:https://www.cnblogs.com/guohuiru/p/3056371.html
Copyright © 2011-2022 走看看