加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 如何处理?_escaped_fragment_ =用于AJAX抓取工具?

发布时间:2020-12-13 16:27:31 所属栏目:PHP教程 来源:网络整理
导读:我正在努力使基于 AJAX的网站对SEO友好.正如在网络上的教程中所建议的那样,我在链接中添加了“漂亮”的href属性: a href =“#!site = contact”data-id =“contact”class =“navlink”контакт / agt ;并且,在默认情况下使用AJAX加载内容的div中,爬
我正在努力使基于 AJAX的网站对SEO友好.正如在网络上的教程中所建议的那样,我在链接中添加了“漂亮”的href属性:< a href =“#!site = contact”data-id =“contact”class =“navlink”>контакт< / a&gt ;并且,在默认情况下使用AJAX加载内容的div中,爬虫的 PHP脚本:
$files = glob('./pages/*.php'); 

foreach ($files as &$file) {
    $file = substr($file,8,-4); 

}

if (isset($_GET['site'])) {
    if (in_array($_GET['site'],$files)) {
        include ("./pages/".$_GET['site'].".php");
    }
}

我有一种感觉,一开始我需要另外从(…)/ index.php?_escaped_fragment_ = site = about中删除_escaped_fragment_ = part,因为否则脚本将无法从URL获取站点值,我对吗?

但是,无论如何,我如何知道抓取工具将漂亮的链接(带有#!的链接)转换为丑陋的链接(包含?_escaped_fragment_ =)?我被告知它会自动发生,我不需要提供这种映射,但是Googlebot的抓取并没有向我提供有关URL发生的任何信息.

Google bot会自动查询?_escaped_fragment_ = urls.

所以来自www.example.com/index.php#!site=about
谷歌机器人将查询:www.example.com/index.php?_escaped_fragment_ = site = about

在PHP网站上,您将获得$_GET [‘_ escaped_fragment_’] =“site = about”

如果你想获得“网站”的价值,你需要做这样的事情:

if(isset($_GET['_escaped_fragment_'])){
    $escaped = explode("=",$_GET['_escaped_fragment_']);
    if(isset($escaped[1]) && in_array($escaped[1],$files)){
          include ("./pages/".$escaped[1].".php");
    }
 }

看看文档:

https://developers.google.com/webmasters/ajax-crawling/docs/specification

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读