步步为营-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>

posted @ 2017-09-17 17:46  逍遥小天狼  阅读(244)  评论(0编辑  收藏  举报