
ptcms SEO配置文件路径
PTCMS的SEO相关配置主要集中在其核心配置文件中。根据官方文档和社区实践,通常位于:
/path/to/ptcms/application/config/
其中包含多个影响SEO的关键文件,如config.php
、seo.php
等。以下为具体配置步骤。
核心SEO参数配置
修改seo.php
文件中的核心参数,这些设置直接影响搜索引擎抓取效果。
return [
'title' => '%s - %s',
'description' => '%s %s',
'keywords' => '%s %s %s',
'canonical' => '%s',
'robots' => 'index,follow',
'noindex' => false,
'nofollow' => false,
'og_title' => '%s',
'og_description'=> '%s',
'og_image' => '%s',
'og_type' => 'website',
'og_url' => '%s',
'twitter_card' => 'summary_large_image',
'twitter_site' => '@%s',
'twitter_title' => '%s',
'twitter_image' => '%s',
];
关键参数说明:
参数 | 功能说明 |
---|---|
title | 页面标题模板,推荐使用%s 代表文章标题,%s 代表网站名称 |
description | 页面描述模板,建议控制在150-200字符内 |
keywords | 页面关键词模板,建议使用3-5个核心关键词 |
canonical | 规范链接,解决重复内容问题 |
robots | 爬虫指令,推荐使用index,follow |
URL重写规则配置
PTCMS使用.htaccess
文件控制URL重写,正确配置可显著提升SEO效果。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.)$ index.php?/$1 [L,QSA]
配置要点:
- 确保Apache服务器开启
mod_rewrite
模块 - 路径需根据实际部署环境修改
- 测试方法:访问
/index.php?route=common/home
应能正常显示首页
多语言网站SEO配置
对于支持多语言的PTCMS网站,需要特殊处理SEO参数。
$config['language'] = array(
'en' => array(
'title' => '%s - English Site',
'description' => 'English description',
'keywords' => 'English, keywords',
'og_title' => '%s - English',
),
'zh' => array(
'title' => '%s - 中文站点',
'description' => '中文站点描述',
'keywords' => '中文, 关键词',
'og_title' => '%s - 中文',
),
);
实现方式:
- 在语言文件中定义不同语言的SEO模板
- 通过路由参数传递当前语言标识
- 模板引擎会自动选择对应语言的配置
生成Sitemap文件方法
PTCMS默认不包含Sitemap生成功能,需要手动添加。
$php /path/to/ptcms/index.php tool/sitemap
生成的Sitemap文件路径:
/path/to/ptcms/public/sitemap.xml
在robots.txt
中添加引用:
Sitemap: https://www.example.com/sitemap.xml
自定义Robots文件配置
在网站根目录创建robots.txt
文件,控制爬虫访问权限。
User-agent:
Disallow: /admin/
Disallow: /install/
Disallow: /cache/
Disallow: /system/
Sitemap: https://www.example.com/sitemap.xml
重要指令说明:
指令 | 说明 |
---|---|
User-agent: | 匹配所有爬虫 |
Disallow: /admin/ | 禁止访问后台目录 |
Sitemap: https://www.example.com/sitemap.xml | 提交Sitemap文件给搜索引擎 |
图片SEO优化配置
PTCMS的图片SEO优化主要通过配置文件实现。
$config['image'] = array(
'alt' => true,
'title' => true,
'size' => '1200x630',
'quality' => 90,
'watermark' => false,
'watermark_text' => '© %s',
'watermark_pos' => 'bottom-right',
);
关键配置说明:
alt
:是否自动添加alt属性title
:是否自动添加title属性size
:默认图片尺寸watermark
:是否添加水印
网站速度优化配置
PTCMS提供多种速度优化配置选项。
$config['speed'] = array(
'cache' => true,
'cache_time' => 3600,
'gzip' => true,
'expires' => 604800,
'lazyload' => true,
'minify' => true,
'minify_js' => true,
'minify_css' => true,
'minify_html' => true,
);
配置说明:
参数 | 说明 |
---|---|
cache | 是否启用页面缓存 |
cache_time | 缓存有效期(秒) |
gzip | 是否启用Gzip压缩 |
expires | 浏览器缓存有效期(秒) |
lazyload | 是否启用图片懒加载 |
minify | 是否启用资源压缩 |
结构化数据配置
PTCMS支持多种结构化数据格式。
{
"schema_type": "jsonld",
"items": [
{
"@context": "https://schema.org",
"@type": "Article",
"headline": "%s",
"image": "%s",
"author": {
"@type": "Person",
"name": "%s"
},
"datePublished": "%s",
"publisher": {
"@type": "Organization",
"name": "%s",
"logo": {
"@type": "ImageObject",
"url": "%s"
}
}
}
]
}
配置步骤:
- 在模板文件中引入结构化数据
- 确保所有必要字段都有值
- 使用Google结构化数据测试工具验证
移动端适配配置
PTCMS提供移动端适配配置。
$config['mobile'] = array(
'detect' => true,
'template' => 'mobile',
'viewport' => 'width=device-width, initial-scale=1.0',
'touch' => true,
'nightmode' => false,
);
关键配置说明:
参数 | 说明 |
---|---|
detect | 是否自动检测移动设备 |
template | 移动端模板名称 |
viewport | meta viewport设置 |
内部链接优化配置
PTCMS支持多种内部链接优化配置。
$config['internal'] = array(
'rewrite' => true,
'rel' => 'nofollow',
'nofollow' => false,
'dofollow' => true,
'priority' => 0.5,
'frequency' => 'monthly',
);
配置说明:
参数 | 说明 |
---|---|
rewrite | 是否启用URL重写 |
rel | 默认内部链接rel属性 |