pbootcms规则下的链接301重定向到自定义URL
这个项目有个重新定义URL的功能,现在我发现重新定义URL后,原来链接依然可以访问,这对谷歌搜索引擎来说非常不友好,我需要怎么处理呢
apps\home\controller\IndexController.php
添加
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| use app\home\service\RedirectService; private function getContent($data) { if (! ! $sort = $this->model->getSort($data->scode)) { if ($sort->contenttpl) { $this->checkPageLevel($sort->gcode, $sort->gtype, $sort->gnote); $this->checkPageLevel($data->gcode, $data->gtype, $data->gnote);
RedirectService::toStandardUrl( $data, 'content', $this->parser); $content = parent::parser($this->htmldir . $sort->contenttpl); $content = $this->parser->parserBefore($content); $content = str_replace('{pboot:pagetitle}', $this->config('content_title') ?: '{content:title}-{sort:name}-{pboot:sitetitle}-{pboot:sitesubtitle}', $content); $content = str_replace('{pboot:pagekeywords}', '{content:keywords}', $content); $content = str_replace('{pboot:pagedescription}', '{content:description}', $content); $content = $this->parser->parserPositionLabel($content, $sort->scode); $content = $this->parser->parserSortLabel($content, $sort); $content = $this->parser->parserCurrentContentLabel($content, $sort, $data); $content = $this->parser->parserCommentLabel($content); $content = $this->parser->parserAfter($content); } else { error('请到后台设置分类栏目内容页模板!'); } } else { _404('您访问内容的分类已经不存在,请核对后再试!'); } $this->cache($content, true); }
|
在home下面建service文件夹创建RedirectService.php
apps\home\service\RedirectService.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| <?php namespace app\home\service; use core\basic\Url;
class RedirectService { public static function toStandardUrl($data, $type = 'content', $parser = null) { $parser = $parser ?: new \app\home\controller\ParserController(); $request_url = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); $new_url = $parser->parserLink( $data->type, $data->urlname, $type, $data->scode, $data->sortfilename, $data->id ?? '', $data->filename );
if ($request_url && $request_url != $new_url) { header("HTTP/1.1 301 Moved Permanently"); header("Location: " . $new_url); exit; } } }
|