---
title: "discuzx2.5 分区 SEO设置"
author: "phpseyo"
date: "2012-09-28T19:42:19Z"
tags: []
categories: ["行业应用"]
slug: "discuzx2-5-seo"
draft: false
lastmod: "2012-10-15T17:09:01Z"
id: 1688236
url: "https://phpseyo.iteye.com/blog/1688236"
---

由于DiscuzX2.5后台没有分区的SEO设置，只能自己动手改了。

要实现如下效果：

 

请求路径 xxx/forum-gid-2.html 实际访问 xxx/forum.php?gid=2

 

下面分别是针对apache及nginx的rewrite

 

apache:

RewriteRule ^forum-gid-(\[0-9]+)\\.html$ forum.php?gid=$1

 

Nginx:

 

rewrite ^/forum-gid-(\[0-9]+).html$ /forum.php?gid=$1;

 

另外还要对原有的链接进行 301 跳转：

 

Nginx:

    if ($request\_uri ~* "^/forum.php\\?gid=(\\d+)$") {

                set $param1 $1;

                rewrite (.\*) /forum-gid-$param1.html? permanent;

    }

然后修改如下文件：

template\\default\\forum\\ajax\_forumlist.htm

template\\default\\forum\\discuz.htm

template\\default\\forum\\post\_forumselect.htm

template\\default\\forum\\stat\_team.htm

(其实就是在template文件夹中全局搜索 forum.php?gid 这串字符)

然后把文件中的 forum.php?gid=$gid 改成 forum-gid-$gid.html