分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 教程案例

步步为营-90-SEO(url重写+超链接技巧)

发布时间:2023-09-06 01:11责任编辑:蔡小小关键词:urlSEO

目的:便于搜索引擎抓取

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>

步步为营-90-SEO(url重写+超链接技巧)

原文地址:http://www.cnblogs.com/YK2012/p/7536436.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved