CakePHP 搜索引擎优化插件

安装: 61

依赖项: 0

建议者: 0

安全: 0

星标: 1

关注者: 3

分支: 2

开放问题: 0

类型:cakephp-plugin

dev-master / 2.x-dev 2014-12-23 21:50 UTC

This package is not auto-updated.

Last update: 2024-09-28 15:12:14 UTC


README

Build Status Coverage Status Total Downloads Latest Stable Version

CakePHP-Seo-Plugin

需求

  • CakePHP 2.x
  • PHP 5.3+

安装

[使用 Composer]

将插件添加到项目的 composer.json 文件中 - 例如:

  {
    "require": {
      "stonelasley/seo": "dev-master"
    }
  }

因为这个插件在它的 composer.json 中设置了类型 cakephp-plugin,所以 Composer 会将它安装到你的 /Plugins 目录中,而不是常规的 vendors 文件中。建议将 /Plugins/CakePHP-Seo-Plugin 添加到你的 .gitignore 文件中。(为什么?阅读此内容。)

[手动]

[GIT Submodule]

在你的应用目录中输入

  git submodule add -b master git://github.com/stonelasley/seo.git Plugin/Seo
  git submodule init
  git submodule update

[GIT Clone]

在你的 Plugin 目录中输入

git clone -b master git://github.com/stonelasley/seo.git Seo

启用插件

在 2.0 中,你需要在你 app/Config/bootstrap.php 文件中启用插件

CakePlugin::load('Seo');

如果你已经使用了 CakePlugin::loadAll();,则此步骤不是必需的。

功能

满足你所有 CakePHP 搜索引擎优化需求的全功能工具

  • 易于使用且功能强大的 301 重定向工具,仅在发生 404 错误时加载
  • 高度可配置且智能的 404 深度 URL 猜测,利用 levenshtein 距离和你的 sitemap.xml
  • 高度可配置和可自定义的 Meta 标签,适用于任何传入的 URI
  • 基于 URI 的标题标签覆盖
  • 基于 URI 的自定义状态码
  • 抓取器禁止管理,包括 honeyPot 饵料,让抓取器自己禁止自己。
  • 基于 URI 的 Google Analytics AB 测试管理

设置

创建文件 app/config/seo.php,配置如下:

<?php
$config = array(
	'Seo' => array(
		'approverEmail' => 'admin@example.com',
		'replyEmail' => 'noreply@example.com',
		'parentDomain' => 'http://www.example.com',
		'triggerCount' => 2,
		'timeBetweenTriggers' => 60 * 60 * 24, //seconds
		'aggressive' => true, //if false, log affenders for later review instead of autobanning
		'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'
		'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, a sitemap
		),
		'abTesting' => array(
			'category' => 'ABTest', //Category for your ABTesting in Google Analytics
			'scope' => 3, //Scope for your ABTesting in Google Analytics
			'legacy' => false, //Uses Legacy verion of Google Analytics JS code pageTracker._setCustomVar(...)
			'session' => true, //Uses CakeSession to serve same test to uses who have seen them.
		)
	)
);
?>

用法

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

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

<?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 辅助器包含到 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 辅助器包含到 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 辅助器包含到 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

技巧:将 A/B 测试设置为调试,它将在控制器中返回 true,但您不会跟踪 GA 代码。

待办事项

许可

MIT 许可证 (MIT)

在此特此授予任何获得本软件及其相关文档文件(“软件”)副本的人免费处理软件的权利,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或出售软件副本的权利,并允许获得软件的人这样做,但受以下条件的约束

上述版权声明和本许可声明应包含在软件的所有副本或主要部分中。

软件按“原样”提供,不提供任何形式的保证,明示或暗示,包括但不限于适销性、特定用途的适用性和非侵权性保证。在任何情况下,作者或版权所有者不应对任何索赔、损害或其他责任承担责任,无论该责任基于合同、侵权或其他方式,无论是源于、因之或与此软件或软件的使用或其他交易有关。