包含伪静态规则设置、内容迁移方案及优化建议。
PS:目前万事屋暂时不考虑搬迁,技术文章什么的,b2实在想不出怎么分类
第一部分:伪静态规则转换
B2主题伪静态规则(Nginx)
# ======================================================
# WordPress B2主题优化伪静态规则
# 兼容WP Super Cache | Nginx 1.26+
# ======================================================
# 核心缓存控制变量
set $supercache_skip 0;
# 动态请求排除条件
if ($request_method = POST) { set $supercache_skip 1; }
if ($query_string != "") { set $supercache_skip 1; }
if ($http_cookie ~* "(comment_author|wordpress_logged_in|wp_postpass|woocommerce_cart_hash)") {
set $supercache_skip 1;
}
# B2主题动态路径排除
if ($request_uri ~* "(^/user/|^/shop/|^/credit/|^/task/|^/vip/|^/question/|^/add-article|^/add-url|^/add-topic|^/messages|^/follow|^/fans|^/collect|^/b2_ajax|^/b2pay)") {
set $supercache_skip 1;
}
# B2主题API端点处理
location ~ ^/(b2_ajax|b2pay) {
try_files $uri $uri/ /index.php?$args$is_args$args;
}
# 用户中心路由处理
location ~ ^/user/(.*) {
try_files $uri $uri/ /index.php?user=$1&$args;
}
# 商城路由处理
location ~ ^/shop/(.*) {
try_files $uri $uri/ /index.php?shop=$1&$args;
}
# 主处理块
location / {
# 尝试提供超级缓存文件或回退到WordPress
try_files /wp-content/cache/supercache/$http_host/$uri/index.html $uri $uri/ @nocache;
}
# 缓存跳过处理
location @nocache {
try_files $uri $uri/ /index.php?$args;
}
# ========================
# 增强功能配置
# ========================
# 静态资源长期缓存
location ~* .(js|css|png|jpg|jpeg|gif|ico|svg|webp|woff2|woff|ttf)$ {
expires 365d;
add_header Cache-Control "public, immutable";
add_header Access-Control-Allow-Origin "*";
access_log off;
}
# 管理后台重定向
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
# 安全设置
location ~* (wp-config.php|readme.html|license.txt|.htaccess) {
deny all;
access_log off;
}
# 禁止访问隐藏文件
location ~ /.(?!well-known) {
deny all;
access_log off;
log_not_found off;
}
# 防止缓存动态内容
location ~* (wp-admin|wp-login|user|shop|credit|task|vip|messages|b2_ajax|b2pay) {
expires off;
add_header Cache-Control "no-cache, no-store, must-revalidate";
}
安装步骤:
- 在宝塔面板中:网站 → 设置 → 伪静态
- 完全清空现有内容
- 粘贴上述B2主题规则
- 保存并重载Nginx
- 在WordPress后台:设置 → 固定链接 → 保存更改
第二部分:迁移”生活”板块内容到文章分类
方法1:使用插件迁移(推荐)
- 安装插件:
- 安装并激活「Post Type Switcher」插件
- 安装并激活「Taxonomy Switcher」插件
- 迁移步骤:
- 进入子比社区”生活”板块列表页
- 全选所有内容 → 批量操作 → 编辑 → 应用
- 在”文章类型”中选择”文章”(Post)
- 在”分类”中选择”生活”分类(如不存在需先创建)
- 点击”更新”
方法2:使用SQL迁移(高效但需谨慎)
-- 步骤1:创建"生活"分类(如不存在)
INSERT INTO wp_terms (name, slug, term_group)
VALUES ('生活', 'life', 0);
SET @term_id = LAST_INSERT_ID();
INSERT INTO wp_term_taxonomy (term_id, taxonomy, description, parent, count)
VALUES (@term_id, 'category', '', 0, 0);
-- 步骤2:迁移内容
UPDATE wp_posts p
JOIN wp_term_relationships tr ON p.ID = tr.object_id
JOIN wp_term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id
JOIN wp_terms t ON tt.term_id = t.term_id
SET p.post_type = 'post'
WHERE
t.name = '生活' AND
tt.taxonomy = 'your_custom_taxonomy' AND -- 替换为子比的实际分类法名称
p.post_type = 'your_custom_post_type'; -- 替换为子比的实际文章类型
警告:执行SQL前请务必备份数据库!
方法3:手动迁移(小批量内容适用)
- 进入子比社区”生活”板块
- 打开要迁移的帖子 → 全选内容复制
- 新建文章 → 粘贴内容 → 设置分类为”生活”
- 保存发布
建议:对于超过20篇内容的情况,使用插件或SQL方法更高效
第三部分:B2主题优化建议
必备插件:
- Redis Object Cache – 数据库缓存加速
- WP Super Cache – 静态页面缓存
- B2主题专用优化插件(如B2扩展插件)
性能优化设置:
# 在Nginx配置中添加
location ~* .(js|css|png|jpe?g|gif|ico|webp)$ {
add_header Cache-Control "public, max-age=31536000, immutable";
access_log off;
expires 1y;
}
# PHP处理优化
location ~ [^/].php(/|$) {
fastcgi_pass unix:/tmp/php-cgi-82.sock;
fastcgi_index index.php;
include fastcgi.conf;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_read_timeout 300;
}
迁移后检查清单:
- URL重定向:设置301重定向,将旧的子比链接指向新位置
# 重定向示例 rewrite ^/community/life/(.*)$ /category/life/$1 permanent;
- 内容验证:
- 检查所有图片和媒体文件是否正常显示
- 测试所有内部链接是否有效
- 验证分类和标签是否正确迁移
- SEO维护:
- 更新XML站点地图
- 提交新URL到搜索引擎
- 设置404监控
常见问题解决
1. 迁移后分类不显示
-- 修复分类计数
UPDATE wp_term_taxonomy SET count = (
SELECT COUNT(*) FROM wp_term_relationships
WHERE term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id
);
2. 用户角色权限问题
在B2主题设置中:
- 进入”用户设置”
- 确保”生活”分类的发布权限已分配给相应用户组
- 检查角色能力设置
3. 缓存冲突处理
- 在WP Super Cache中排除B2动态路径:
^/user/.* ^/shop/.* ^/b2_ajax/.* ^/messages/.*
- 清除所有缓存:
rm -rf /www/wwwroot/yoursite/wp-content/cache/* service nginx restart service php-fpm restart
迁移完成提示
完成以上步骤后,您的网站应该已成功从子比主题迁移到B2主题,并且”生活”板块内容已完整转移到文章分类中。
迁移后建议监控网站性能和用户反馈一周,根据实际情况微调设置。