帝国CMS在Nginx环境下实现伪静态,需要正确配置Nginx的重写规则(rewrite),让URL看起来更友好,同时确保系统能正常解析动态请求。以下是常见的帝国CMS Nginx伪静态规则写法。

1. 基础伪静态规则

适用于大多数帝国CMS站点,将常见栏目、内容页、列表页等URL进行重写:

location / {

rewrite ^/index\.html$ /index.php last;

rewrite ^/list-([0-9]+)-([0-9]+)\.html$ /index.php?classid=$1&page=$2 last;

rewrite ^/list-([0-9]+)\.html$ /index.php?classid=$1 last;

rewrite ^/show-([0-9]+)-([0-9]+)-([0-9]+)\.html$ /index.php?classid=$1&id=$2&page=$3 last;

rewrite ^/show-([0-9]+)-([0-9]+)\.html$ /index.php?classid=$1&id=$2 last;

rewrite ^/tags/([^/]*)\.html$ /e/tags/index.php?tagname=$1 last;

rewrite ^/search/(.*)$ /e/search/index.php?$1 last;

}

2. 自定义字段或特殊页面规则

如果你有自定义的栏目链接、专题页或其他扩展功能,可添加如下规则:

# 专题页

rewrite ^/zt/([0-9]+)\.html$ /special/index.php?id=$1 last;

<h1>用户中心</h1><p>rewrite ^/user/(.*)$ /e/member/$1 last;</p><h1>投票功能</h1><p>rewrite ^/vote/([0-9]+).html$ /e/vote/index.php?voteid= last;</p><div class="aritcle_card flexRow">

<div class="artcardd flexRow">

<a class="aritcle_card_img" href="/ai/1154" title="Motiff"><img

src="https://img.php.cn/upload/ai_manual/000/000/000/175680126049574.png" alt="Motiff"  onerror="this.onerror='';this.src='/static/lhimages/moren/morentu.png'" ></a>

<div class="aritcle_card_info flexColumn">

<a href="/ai/1154" title="Motiff">Motiff</a>

<p>Motiff是由猿辅导旗下的一款界面设计工具,定位为“AI时代设计工具”</p>

</div>

<a href="/ai/1154" title="Motiff" class="aritcle_card_btn flexRow flexcenter"><b></b><span>下载</span> </a>

</div>

</div>

3. 静态资源排除

避免静态文件被重写规则干扰,建议加上对图片、CSS、JS等文件的判断:

location ~* \.(gif|jpg|jpeg|png|css|js|ico)$ {

expires 30d;

access_log off;

add_header Cache-Control "public";

break;

}

4. EmpireCMS后台访问保护

为安全起见,可限制后台访问路径:

location /e/admin/ {

allow 192.168.1.1;  # 允许IP

deny all;

}

注意事项:

以上规则需写入你的站点配置文件中,通常位于 /etc/nginx/sites-available/your-site

修改后运行 nginx -t 检查语法,再 reload:nginx -s reload

帝国后台必须开启“伪静态”选项,并设置对应的URL格式(如 show-{$classid}-{$id}.html)

如果使用子目录安装,需调整路径前缀,例如 rewrite ^/cms/show-(\d+)-(\d+)\.html