解决SPA网页对SEO不友好的问题
阅读 284 作者 zee

基于vuejs等框架编写的但页面应用往往对seo不太友好,那怎么办呢?大多数的办法就是把所有不存在的页面重定向到首页,以便支持显示。

首先要配置nginx环境,把非真实存在的文件重新定向到 “index.php” 或者 “/”。

location / {
   try_files $uri $uri/ /;
}

然后编写index.php

<?php
$uri  = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$maps = [
    "/about/intro"      => ["title" => "企业简介"],
    "/about/teacther"   => ["title" => "师资力量"],
    "/about/job"        => ["title" => "诚聘精英"],
    "/school"           => ["title" => "校区分布"],
    "/course"           => ["title" => "课程体系"],
    "/news"             => ["title" => "学校动态"],
    "/race"             => ["title" => "活动竞赛"],
    "/exchange"         => ["title" => "对外交流"],
    "/duty"             => ["title" => "社会责任"],
    "/school/student"   => ["title" => "优秀学员"],
    "/school/say"       => ["title" => "学员感言"],
    "/school/comment"   => ["title" => "家长评价"],
    "/school/classroom" => ["title" => "精彩课堂"],
    "/join/value"       => ["title" => "加盟我们"],
];
$title = "艾克瑞特机器人教育";
if (isset($maps[$uri])) {
    $title = $maps[$uri]["title"] . " - " . $title;
} else {
    $title = "艾克瑞特机器人培训机构,机器人教育加盟-12年专注机器人教育";
}
?>

然后直接调用<?=$title?>变量即可。

这个代码可以自行增加关键字或描述等其他字段信息。

 

[编辑于 2019/08/08 15:47]