栏目URL伪静态概述
织梦CMS的栏目URL伪静态是指将栏目列表页的动态URL(如 /plus/list.php?tid=3)转换为静态形式的URL(如 /news/ 或 /news/list_2.html),对SEO友好且便于用户记忆。织梦CMS支持默认伪静态、自定义规则等多种方式。
一、开启织梦CMS伪静态功能
在系统参数中启用伪静态:
- 进入
系统 > 系统基本参数 - 找到"核心设置"选项卡
- 设置以下参数:
是否使用伪静态: 是 列表页伪静态规则: list-[ページ]/ 内容页伪静态规则: [ID].html (注意:不同版本参数名可能略有不同)
二、Apache伪静态规则(.htaccess)
在网站根目录创建或编辑 .htaccess 文件:
RewriteEngine On RewriteBase / # 栏目列表页伪静态 RewriteRule ^(.*)/list-([0-9]+)\.html$ /plus/list.php?tid=$1&PageNo=$2 [L] RewriteRule ^(.*)/$ /plus/list.php?tid=$1 [L] # 文章内容页伪静态 RewriteRule ^(.*)/([0-9]+)\.html$ /plus/view.php?aid=$2 [L] # 搜索结果伪静态 RewriteRule ^search/(.*)\.html$ /plus/search.php?q=$1 [L] # TAG页伪静态 RewriteRule ^tags/(.*)/$ /tags.php?/$1 [L]
三、Nginx伪静态规则
在Nginx配置文件中添加:
location / {
# 栏目列表页
rewrite "^/([a-zA-Z0-9_\-]+)/list-([0-9]+)\.html$" /plus/list.php?tid=$1&PageNo=$2 last;
rewrite "^/([a-zA-Z0-9_\-]+)/$" /plus/list.php?tid=$1 last;
# 文章内容页
rewrite "^/([a-zA-Z0-9_\-]+)/([0-9]+)\.html$" /plus/view.php?aid=$2 last;
# 搜索页
rewrite "^/search/(.*)\.html$" /plus/search.php?q=$1 last;
}
四、IIS伪静态规则(web.config)
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="栏目列表页">
<match url="^([a-zA-Z0-9_\-]+)/list-([0-9]+)\.html$" />
<action type="Rewrite" url="/plus/list.php?tid={R:1}&PageNo={R:2}" />
</rule>
<rule name="文章内容页">
<match url="^([a-zA-Z0-9_\-]+)/([0-9]+)\.html$" />
<action type="Rewrite" url="/plus/view.php?aid={R:2}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
五、自定义栏目URL格式
修改 include/helpers/channelunit.helper.php 中的URL生成函数:
<?php
// 自定义栏目URL生成规则
function GetTypeUrl($typeid, $typedir, $isdefault, $defaultname,
$ispart, $namerule2, $moresite=0, $siteurl='', $sitepath='')
{
// 自定义:让栏目URL变为 /栏目拼音.html
$typename=GetTypeName($typeid);
$pinyin=GetPinyin($typename); // 需要自定义拼音转换函数
return $GLOBALS['cfg_basehost'].'/'.$pinyin.'.html';
}
六、栏目URL的常见设置方案
| 方案 | URL格式 | 说明 |
|---|---|---|
| 默认静态 | /news/index.html | 全静态HTML |
| 目录形式 | /news/ | 以目录名访问 |
| 伪静态带分页 | /news/list_2.html | 支持分页 |
| 全动态 | /plus/list.php?tid=3 | 不推荐 |
推荐方案:对于SEO优化,推荐使用栏目目录+伪静态的组合方案。栏目首页使用
/news/ 形式,分页使用 /news/list_2.html,文章使用 /news/123.html 形式。这种方案URL简洁、层级清晰,对搜索引擎最友好。