webtechnick/cakephp-seo-plugin

CakePHP 搜索引擎优化插件

dev-master / 2.x-dev 2018-02-13 14:01 UTC

This package is not auto-updated.

Last update: 2024-09-28 14:37:56 UTC


README

特性

满足您所有 CakePHP 搜索引擎优化需求的完整工具

  • 易于使用且功能强大的 301 重定向工具,仅在发生 404 错误时加载
  • 高度可配置和智能的 404 深层 URL 猜测,利用 Levenshtein 距离和您的 sitemap.xml
  • 高度可配置和可定制的 Meta 标签,适用于任何传入 URI
  • 基于 URI 的标题标签覆盖
  • 基于 URI 的自定义状态码
  • 爬虫禁止管理,包括用于引诱爬虫自行禁止的 HoneyPot
  • 基于 URI 的 Google Analytics AB 测试管理

变更日志

  • 6.2.1 清理和错误修复,不再有重复错误。新增 SeoRedirects 的 is_nocache 布尔值。
  • 6.2.0 新增 SeoABTesting,更新您的 Config/seo.php 文件
  • 6.1.0 新增特殊情况的 200 状态码,以返回 noindex,比 410 更易于且带宽更低地删除 URL
  • 6.0.0 更新以兼容 CakePHP 2.0
  • 5.1.0 新增 SeoUrls Shell,可按需运行 sitemap levenshtein 导入。
  • 5.0.0 新增 Levenshtein 距离公式,以根据 404 请求最佳猜测合适的 301。这仅在配置中激活(默认为 false)且没有 301 重定向规则可以捕获它时发生。
  • 4.5.1 修复了通配符 URI 匹配错误,通配符现在从基础路径开始匹配,例如 /user* 不会匹配 /users/login。
  • 4.5.0 新增 Seo Canonical,使 SEO 能够像 Seo Title 工具一样链接任何 URL。
  • 4.4.0 新增 Seo Status Codes,使 SEO 能够根据 URI 返回 410 或任何其他错误代码。
  • 4.3.0 SeoHelper::metaTags 现在接受一个关联数组作为默认元标签使用(SEO 标签具有优先级)
  • 4.2.x 错误修复和更新,请更新配置文件
  • 4.0.0 添加黑名单
  • 1.0.0 首次发布

安装

将仓库克隆到您的 app/Plugin/Seo 目录中

$ git clone git://github.com/webtechnick/CakePHP-Seo-Plugin.git app/Plugin/Seo

将模式运行到您的数据库中

$ cake schema create --plugin Seo

设置

创建文件 app/Config/seo.php,并添加以下配置,例如:

$config = array(
	'Seo' => array(
		'approverEmail' => 'nick@example.com',
		'replyEmail' => 'noreply@example.com',
		'emailConfig' => 'default', //config of your email, if false will use default CakeEmail()
		'parentDomain' => 'http://www.example.com',
		'aggressive' => true, //if false, log affenders for later review instead of autobanning
		'triggerCount' => 2,
		'timeBetweenTriggers' => 60 * 60 * 24, //seconds
		'honeyPot' => array('admin' => false, 'plugin' => 'seo', 'controller' => 'seo_blacklists', 'action' => 'honeypot'),
		'log' => true,
		'cacheEngine' => false, // optionally cache things to save on DB requests - eg: 'default'
		'searchTerms' => true, //turn on term finding
		'levenshtein' => array(
			'active' => false,
			'threshold' => 5, //-1 to ALWAYS find the closest match
			'cost_add' => 1, //cost to add a character, higher the amount the less you can add to find a match
			'cost_change' => 1, //cost to change a character, higher the amount the less you can change to find a match
			'cost_delete' => 1, //cost to delete a character, higher the ammount the less you can delete to find a match 
			'source' => '/sitemap.xml' //URL to list of urls in a sitemap
		),
		'abTesting' => array(
			'category' => 'ABTest', //Category for your ABTesting in Google Analytics
			'scope' => 3, //Scope for your ABTesting in Google Analytics
			'slot' => 4, //Slot for your ABTesting in Google Analytics
			'legacy' => false, //Uses Legacy verion of Google Analytics JS code pageTracker._setCustomVar(...)
			'session' => true, //will use sessions to store tests for users who've already seen them.
			'redmine' => false, //or the full URL if your redmine http://www.redmine-example.com/issues/
		)
	)
);

SEO 重定向/状态码快速入门

更新文件 app/Config/core.php,例如:

Configure::write('Exception', array(
	'handler' => 'SeoExceptionHandler::handle',
	'renderer' => 'ExceptionRenderer',
	'log' => true
));

更新文件 app/Config/bootstrap.php,例如:

require_once(APP . 'Plugin' . DS . 'Seo' . DS . 'Lib' . DS . 'Error' . DS . 'SeoAppError.php');

添加重定向

http://www.example.com/admin/seo/seo_redirects/

添加状态码

http://www.example.com/admin/seo/seo_status_codes/

注意:特殊状态码 200 将返回最小带宽的 noindex 机器人页面,用于替代 URL 删除(410 替代方案)

SEO Meta 标签快速入门

Seo.Seo Helper 包含到您的 AppController.php

var $helpers = array('Seo.Seo');

修改您的布局以在布局的头部包含 Seo Meta 标签

<head>
	<!-- other head items -->
	<?php echo $this->Seo->metaTags(); ?>
</head>

添加 Meta 标签

http://www.example.com/admin/seo/seo_meta_tags

SEO 标题快速入门

Seo.Seo Helper 包含到您的 AppController.php

var $helpers = array('Seo.Seo');

修改您的布局以在布局的头部包含 Seo 标题

<head>
	<!-- other head items -->
	<?php echo $this->Seo->title($title_for_layout); ?>
</head>

添加标题标签

http://www.example.com/admin/seo/seo_titles

SEO Canonical 快速入门

Seo.Seo Helper 包含到您的 AppController.php

var $helpers = array('Seo.Seo');

修改您的布局以在布局的头部包含 Seo Canonical

<head>
	<!-- other head items -->
	<?php echo $this->Seo->canonical(); ?>
</head>

添加 Canonical 链接

http://www.example.com/admin/seo/seo_canonicals

SEO黑名单快速入门

在您的 AppController.php 中包含 Seo.BlackList 组件

var $components = array('Seo.BlackList');

开始在您的应用程序中添加蜜罐链接,以诱捕恶意内容抓取者

<?php echo $this->Seo->honeyPot(); ?>

更新您的 robots.txt 文件,排除 /seo/ 目录被蜘蛛抓取。所有合法的蜘蛛都将忽略蜜罐

User-agent: *
Disallow: /seo/

添加/管理禁止的IP地址

http://www.example.com/admin/seo/seo_blacklists

SEO A/B 测试快速入门

Seo.Seo 助手和 Seo.ABTest 组件包含到您的 AppController.php

var $helpers = array('Seo.Seo');
var $components = array('Seo.ABTest');

在您网站上的 GA 代码中添加如下行

<script type="text/javascript">
	<!-- GA Items -->
	var pageTracker = _gat._getTracker('UA-SOMEKEY');
	<?php echo $this->Seo->getABTestJS(); ?>
</script>

在您的 AppController.php 中,测试您是否在可测试的页面上,并提供如下操作

public function beforeFilter(){
	if($test = $this->ABTest->getTest()){
		//Do things specific to this test
		$this->set('ABTest', $test);
		$this->view = $test['SeoABTest']['slug'];
	}
	return parent::beforeFilter();
}

专业技巧:在GA上线前,在控制器中进行调试,将调试标志设置为true,这将返回尚未激活的测试。

$test = $this->SeoABTest->getTest(array('debug' => true));

添加A/B测试

http://www.example.com/admin/seo/seo_a_b_tests

专业技巧:将AB测试设置为调试模式,在控制器中将返回true,但您不会跟踪GA代码。

维基链接