帝国CMS在Nginx下实现伪静态需配置重写规则,首先设置基础规则:将index.html、list-.html、show-.html等URL重写到index.php解析;其次添加自定义规则支持专题页、用户中心和投票功能;然后排除静态资源文件(如CSS、JS、图片)避免被重写;最后可限制后台访问IP以增强安全。所有规则需写入站点配置文件,修改后测试语法并重载Nginx,同时确保后台开启伪静态并匹配URL格式,子目录安装时调整路径前缀即可生效。

帝国CMS在Nginx环境下实现伪静态,需要正确配置Nginx的重写规则(rewrite),让URL看起来更友好,同时确保系统能正常解析动态请求。以下是常见的帝国CMS Nginx伪静态规则写法。
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;
}
# 专题页
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">
<a class="aritcle_card_img" href="/ai/trae%E5%9B%BD%E5%86%85%E7%89%88">
<img src="https://img.php.cn/upload/ai_manual/001/246/273/68b6d112d0513186.png" alt="Trae国内版">
</a>
<div class="aritcle_card_info">
<a href="/ai/trae%E5%9B%BD%E5%86%85%E7%89%88">Trae国内版</a>
<p>国内首款AI原生IDE,专为中国开发者打造</p>
<div class="">
<img src="/static/images/card_xiazai.png" alt="Trae国内版">
<span>815</span>
</div>
</div>
<a href="/ai/trae%E5%9B%BD%E5%86%85%E7%89%88" class="aritcle_card_btn">
<span>查看详情</span>
<img src="/static/images/cardxiayige-3.png" alt="Trae国内版">
</a>
</div>
location ~* \.(gif|jpg|jpeg|png|css|js|ico)$ {
expires 30d;
access_log off;
add_header Cache-Control "public";
break;
}
location /e/admin/ {
allow 192.168.1.1; # 允许IP
deny all;
}
注意事项:
/etc/nginx/sites-available/your-site
nginx -t 检查语法,再 reload:nginx -s reload
rewrite ^/cms/show-(\d+)-(\d+)\.html
基本上就这些,不复杂但容易忽略细节。只要前后端设置一致,Nginx规则就能顺利生效。
以上就是帝国cms在Nginx环境下伪静态规则怎么写_帝国cms Nginx伪静态规则写法的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号