帝国 CMS 伪静态规则详细配置教程|Nginx/Apache/IIS 全适配
时间:2026-08-24 19:40:37 来源:aliz.cn 作者:SKY 阅读:
前言
伪静态是帝国 CMS 建站必不可少的配置,将动态
*.php?id=123 地址转为静态类 URL,有利于 SEO 收录,URL 简洁美观。 很多站长配置伪静态后出现:页面 404、栏目打不开、TAG 失效、搜索报错、分页异常,大多是两个原因:①服务器规则写错;②后台系统参数没有开启伪静态。
本文适用版本:帝国 CMS7.5、帝国 CMS8.0,覆盖 Nginx、Apache、IIS 三种主流 web 服务器。
一、帝国 CMS 后台伪静态基础设置(必须先配置)
⚠️顺序:先改后台参数,再配置服务器伪静态规则,不要反过来。
1. 登录帝国 CMS 后台 →【系统】→【系统设置】→【系统参数设置】 2. 找到【伪静态设置】模块
- 开启伪静态:开启
- 信息页伪静态规则、栏目伪静态规则、专题伪静态规则,按自己 URL 格式填写。
示例常用规则(id 模式) 栏目:[!--classid--]/index.html内容页:[!--classid--]/[!--id--].html专题:zt/[!--ztid--]/index.html
3. 保存系统参数。 4. 进入【数据更新中心】,更新栏目缓存、刷新全站缓存。
注意:开启伪静态之后,前台生成的链接全部变成伪静态地址;如果还没配置服务器规则,访问全部会 404。
二、Nginx 伪静态规则(宝塔 Linux,使用最多)
打开宝塔→网站设置→配置文件,将规则写入
server { } 内部。
不要写入 location 里面,写在 server 层级。
基础完整版(栏目、内容页、专题、TAG、搜索)
nginx
if (!-e $request_filename) {
rewrite ^/(.*)/index\.html$ /e/public/Index/index.php?$1 last;
rewrite ^/zt/(.*)/index\.html$ /e/public/Index/ztindex.php?$1 last;
rewrite ^([0-9]+)/([0-9]+)\.html$ /e/public/Index/ShowInfo.php?classid=$1&id=$2 last;
rewrite ^([0-9]+)/index\.html$ /e/public/Index/ListInfo.php?classid=$1 last;
rewrite ^/tag/(.*)$ /e/public/Index/Tag.php?tag=$1 last;
rewrite ^/search/(.*)$ /e/public/Index/Search.php?$1 last;
}
如果你网站安装在子目录(例如 /ecms)
nginx
if (!-e $request_filename) {
rewrite ^/ecms/(.*)/index\.html$ /ecms/e/public/Index/index.php?$1 last;
rewrite ^/ecms/zt/(.*)/index\.html$ /ecms/e/public/Index/ztindex.php?$1 last;
rewrite ^/ecms/([0-9]+)/([0-9]+)\.html$ /ecms/e/public/Index/ShowInfo.php?classid=$1&id=$2 last;
rewrite ^/ecms/([0-9]+)/index\.html$ /ecms/e/public/Index/ListInfo.php?classid=$1 last;
rewrite ^/ecms/tag/(.*)$ /ecms/e/public/Index/Tag.php?tag=$1 last;
rewrite ^/ecms/search/(.*)$ /ecms/e/public/Index/Search.php?$1 last;
}
配置完成校验语法:
bash
nginx -t
无报错执行重载:
bash
nginx -s reload
提示:如果你开启 HTTPS,规则写在 443 端口的 server 块内。
三、Apache 伪静态 .htaccess
网站根目录新建
.htaccess文件,放入下面代码,Apache 需要开启mod_rewrite模块。apache
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)/index\.html$ e/public/Index/index.php?$1 [L]
RewriteRule ^zt/(.*)/index\.html$ e/public/Index/ztindex.php?$1 [L]
RewriteRule ^([0-9]+)/([0-9]+)\.html$ e/public/Index/ShowInfo.php?classid=$1&id=$2 [L]
RewriteRule ^([0-9]+)/index\.html$ e/public/Index/ListInfo.php?classid=$1 [L]
RewriteRule ^tag/(.*)$ e/public/Index/Tag.php?tag=$1 [L]
RewriteRule ^search/(.*)$ e/public/Index/Search.php?$1 [L]
</IfModule>
子目录部署示例,修改
RewriteBase /为你的目录,例如RewriteBase /ecms/。
四、IIS 伪静态 web.config(Windows 服务器)
网站根目录新建
web.config,放入 rewrite 规则。
IIS 需要安装 URL 重写模块。
xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="EmpireCMS1" stopProcessing="true">
<match url="^(.*)/index\.html$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="e/public/Index/index.php?{R:1}" />
</rule>
<rule name="EmpireCMS2" stopProcessing="true">
<match url="^zt/(.*)/index\.html$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="e/public/Index/ztindex.php?{R:1}" />
</rule>
<rule name="EmpireCMS3" stopProcessing="true">
<match url="^([0-9]+)/([0-9]+)\.html$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="e/public/Index/ShowInfo.php?classid={R:1}&id={R:2}" />
</rule>
<rule name="EmpireCMS4" stopProcessing="true">
<match url="^([0-9]+)/index\.html$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="e/public/Index/ListInfo.php?classid={R:1}" />
</rule>
<rule name="EmpireCMS5" stopProcessing="true">
<match url="^tag/(.*)$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="e/public/Index/Tag.php?tag={R:1}" />
</rule>
<rule name="EmpireCMS6" stopProcessing="true">
<match url="^search/(.*)$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="e/public/Index/Search.php?{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
五、自定义 URL 格式适配规则
如果你后台伪静态格式不是classid/id.html,例如拼音文件名、别名 URL,上面默认规则不再适用。 举例:内容页规则[!--classname--]/[!--filename--].html需要修改 Nginx/Apache/IIS 正则表达式,正则要和后台伪静态规则一一对应,后台和服务器正则二者必须匹配,否则 404。
重点提醒:修改后台伪静态格式之后,旧 URL 会失效,需要配置 Nginx 301 重定向把旧地址跳转到新地址,防止收录丢失。
六、伪静态常见问题排查
1、全部页面 404
1)确认服务器重写模块开启:Nginx rewrite、Apache mod_rewrite、IIS URL 重写; 2)规则是否写对层级,Nginx 不要写在 location; 3)后台系统参数是否已经开启伪静态; 4)更新栏目缓存,清除
e/data/tmp缓存。
2、栏目页正常,内容页 404
正则表达式中 classid、id 匹配规则与后台伪静态模板不一致,核对后台伪静态写法。
3、TAG、搜索页面 404
很多网上旧规则缺少 tag 与 search 重写片段,复制本文完整全套规则。
4、伪静态开启后,静态生成页面冲突
开启伪静态之后,不要再生成静态页面,伪静态模式和 HTML 静态模式二选一,不要同时开启。
伪静态模式:访问走 rewrite 转发 php;静态模式:访问真实生成的 html 文件。两者混用会出现页面错乱。
5、宝塔开启伪静态后不生效
检查网站配置是否有重复的 if (!-e) 重写片段,多个 if 会互相冲突,只保留一套帝国 CMS 伪静态。
6、子目录部署伪静态失败
服务器规则与后台伪静态路径都要带上子目录前缀,前后统一。
七、SEO 配套建议
1. 切换伪静态之后,旧动态 URL 做 301 永久重定向,保护百度收录; 2. 重新生成 sitemap,提交搜索引擎; 3. 检查模板内全部链接,确认全部输出伪静态地址; 4. robots.txt 禁止抓取旧动态 php 地址。
本文aliz.cn原创教程,转载请注明来源。
本文配套模板、静态源码可前往艾立兹素材库alisucai.com下载
发表评论
共有0条评论