zoukankan      html  css  js  c++  java
  • 步步为营-90-SEO(url重写+超链接技巧)

    目的:便于搜索引擎抓取

    url重写:将带参数的url如:https://i.cnblogs.com/EditPosts.aspx?opt=1.修改为https://i.cnblogs.com/EditPosts.aspx_1

    1:在BookList修改如下链接方式

     href="<%#Eval("Id","/Goods/BookDetail_{0}.aspx") %>">

    2:添加Global文件

    在Application_BeginRequest方法进行url地址的重写

    protected void Application_BeginRequest(Object sender, EventArgs e)
    {
    string url = Request.AppRelativeCurrentExecutionFilePath;//~/Goods/BookDetail_4939.aspx
    Match match=Regex.Match(url, @"~/Goods/BookDetail_(d+).aspx");
    if (match.Success)
    {
    Context.RewritePath("/Goods/BookDetail.aspx?id="+match.Groups[1].Value);
    }
    }

    超链接技巧:由于SEO执行js脚本

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SeoTest.aspx.cs" Inherits="BookShop.Web.Test.SeoTest" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title></title>
        <script src="../js/jquery-1.7.1.js"></script>
        <script type="text/javascript">
            $(function () {
                $("#a1").click(function () {
                    $.post("/ashx/seo.ashx", {}, function (data) {
                        $("#div1").append(data);
                    });
                    return false;
                });
            });
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <a href="Javascript:void(0)" id="a1">mmm</a>
            <div id="div1"></div>
           
        </div>
        </form>
    </body>
    </html>
    原来的代码
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SeoTest.aspx.cs" Inherits="BookShop.Web.Test.SeoTest" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title></title>
        <script src="../js/jquery-1.7.1.js"></script>
        <script type="text/javascript">
            $(function () {
                $("#a1").click(function () {
                    $.post("/ashx/seo.ashx", {}, function (data) {
                        $("#div1").append(data);
                    });
                    return false;
                });
            });
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <a href="/ashx/seo.ashx" id="a1">mmm</a>
            <div id="div1"></div>
           
        </div>
        </form>
    </body>
    </html>
    修改后

    仅仅修改了: <a href="/ashx/seo.ashx" id="a1">mmm</a>

  • 相关阅读:
    增强学习笔记 第二章 多臂赌博机问题
    学习计划与目标
    2020秋季新学期
    2019春总结作业
    2019春年第四次课程设计实验报告
    2019春年第三次课程设计实验报告
    2019春年第二次课程设计实验报告
    2019春年第一次课程设计实验报告
    2019春第十二周作业
    2019春第十一周作业
  • 原文地址:https://www.cnblogs.com/YK2012/p/7536436.html
Copyright © 2011-2022 走看看