苹果CMS V10多服务器伪静态Rewrite规则与配置实操教程
2024-08-21
共人阅读

苹果CMS V10伪静态URL规则对照表
表格列出全部页面对应的伪静态路由格式,路由里的参数标识支持自定义修改,改动之后需要同步修改程序内URL生成配置和服务器重写规则,保证两边匹配一致。
| 页面类型 | 伪静态规则 |
|---|---|
| 视频地图页 | map |
| 视频分类页 | type/{id}-{pg} |
| 视频内容页 | detail/{id} |
| 视频播放页 | play/{id}-{src}-{num} |
| 视频下载页 | down/{id}-{src}-{num} |
| 视频筛选页 | vod-list-id-{id}-pg-{pg}-order-{order}-by-{by}-class-{class}-year-{year}-letter-{letter}-area-{area}-lang-{lang} |
| 视频专题首页 | topicindex |
| 视频专题列表页 | topiclist/{id}-{pg} |
| 视频搜索页 | search-pg-{pg}-wd-{wd} |
| 文章首页 | artindex |
| 文章分类页 | artlist/{id}-{pg} |
| 文章内容页 | art/{id}-{pg} |
| 文章地图页 | artmap |
| 留言本 | gbook/{pg} |
| 自定义页面 | label/{label} |
| RSS | rss/{method}/{pg} |
各服务器伪静态配置代码
httpd.ini(ISAPI_Rewrite Windows)
适用于搭载ISAPI_Rewrite组件的Windows服务器,将内容保存为httpd.ini放置在站点根目录即可加载生效。
[ISAPI_Rewrite] # 3600 = 1 hour CacheClockRate 3600 RepeatLimit 32 RewriteRule ^type/(.*)-(.*)$ /index.php?m=vod-type-id-$1-pg-$2 [I] RewriteRule ^detail/(.*)$ /index.php?m=vod-detail-id-$1 [I] RewriteRule ^play/(.*)-(.*)-(.*)$ /index.php?m=vod-play-id-$1-src-$2-num-$3 [I] RewriteRule ^down/(.*)-(.*)-(.*)$ /index.php?m=vod-down-id-$1-src-$2-num-$3 [I] RewriteRule ^topiclist/(.*)-(.*)$ /index.php?m=vod-topic-id-$1-pg-$2 [I] RewriteRule ^topicindex(.*)$ /index.php?m=vod-topicindex-pg-$1 [I] RewriteRule ^artindex(.*)$ /index.php?m=art-index-pg-$1 [I] RewriteRule ^artlist/(.*)-(.*)$ /index.php?m=art-type-id-$1-pg-$2 [I] RewriteRule ^art/(.*)-(.*)$ /index.php?m=art-detail-id-$1-pg-$2 [I] RewriteRule ^label/(.*)$ /index.php?m=label-$1 [I] RewriteRule ^map(.*)$ /index.php?m=vod-map$1 [I] RewriteRule ^artmap(.*)$ /index.php?m=art-map$1 [I] RewriteRule ^gbook/(.*)$ /index.php?m=gbook-show-pg-$1 [I] RewriteRule ^search-pg-(.*)-wd-(.*)$ /index.php?m=vod-search-pg-$1-wd-$2 [I] RewriteRule ^rss/(.*)/(.*)$ /index.php?m=map-$1 [I] RewriteRule ^vod-list-id-(.*)-pg-(.*)-order-(.*)-by-(.*)-class-(.*)-year-(.*)-letter-(.*)-area-(.*)-lang-(.*)$ /index.php?m=vod-list-id-$1-pg-$2-wd-$3-area-$4-lang-$5-year-$6-letter-$7-order-$8-by-$9 [I]
.htaccess(Apache)
Apache环境使用.htaccess文件,站点部署在子目录时,修改RewriteBase参数匹配实际路径,根目录直接使用默认配置。
# 开启 RewriteEngine RewriteEngine On # 如果程序安装在子目录,请根据实际目录修改 RewriteBase # 根目录安装通常使用 / RewriteBase / # 苹果CMS系统规则 RewriteRule ^type/(.*)-(.*)$ index.php?m=vod-type-id-$1-pg-$2 RewriteRule ^detail/(.*)$ index.php?m=vod-detail-id-$1 RewriteRule ^play/(.*)-(.*)-(.*)$ index.php?m=vod-play-id-$1-src-$2-num-$3 RewriteRule ^down/(.*)-(.*)-(.*)$ index.php?m=vod-down-id-$1-src-$2-num-$3 RewriteRule ^topiclist/(.*)-(.*)$ index.php?m=vod-topic-id-$1-pg-$2 RewriteRule ^topicindex(.*)$ index.php?m=vod-topicindex-pg-$1 RewriteRule ^artindex(.*)$ index.php?m=art-index-pg-$1 RewriteRule ^artlist/(.*)-(.*)$ index.php?m=art-type-id-$1-pg-$2 RewriteRule ^art/(.*)-(.*)$ index.php?m=art-detail-id-$1-pg-$2 RewriteRule ^label/(.*)$ index.php?m=label-$1 RewriteRule ^map(.*)$ index.php?m=vod-map$1 RewriteRule ^artmap(.*)$ index.php?m=art-map$1 RewriteRule ^gbook/(.*)$ index.php?m=gbook-show-pg-$1 RewriteRule ^search-pg-(.*)-wd-(.*)$ index.php?m=vod-search-pg-$1-wd-$2 RewriteRule ^rss/(.*)/(.*)$ index.php?m=map-$1 RewriteRule ^vod-list-id-(.*)-pg-(.*)-order-(.*)-by-(.*)-class-(.*)-year-(.*)-letter-(.*)-area-(.*)-lang-(.*)$ index.php?m=vod-list-id-$1-pg-$2-wd-$3-area-$4-lang-$5-year-$6-letter-$7-order-$8-by-$9
maccms.conf(Nginx)
Nginx环境导入maccms.conf,根目录与子目录部署写法存在差异,子站点部署时需要调整路由前缀。
# 安装目录: # 1、根目录:/ # 2、子目录:/maccms8_syb/ rewrite ^/type/(.*)-(.*)$ index.php?m=vod-type-id-$1-pg-$2 break; rewrite ^/detail/(.*)$ index.php?m=vod-detail-id-$1 break; rewrite ^/play/(.*)-(.*)-(.*)$ index.php?m=vod-play-id-$1-src-$2-num-$3 break; rewrite ^/down/(.*)-(.*)-(.*)$ index.php?m=vod-down-id-$1-src-$2-num-$3 break; rewrite ^/topiclist/(.*)-(.*)$ index.php?m=vod-topic-id-$1-pg-$2 break; rewrite ^/topicindex(.*)$ index.php?m=vod-topicindex-pg-$1 break; rewrite ^/artindex(.*)$ index.php?m=art-index-pg-$1 break; rewrite ^/artlist/(.*)-(.*)$ index.php?m=art-type-id-$1-pg-$2 break; rewrite ^/art/(.*)-(.*)$ index.php?m=art-detail-id-$1-pg-$2 break; rewrite ^/label/(.*)$ index.php?m=label-$1 break; rewrite ^/map(.*)$ index.php?m=vod-map$1 break; rewrite ^/artmap(.*)$ index.php?m=art-map$1 break; rewrite ^/gbook/(.*)$ index.php?m=gbook-show-pg-$1 break; rewrite ^/search-pg-(.*)-wd-(.*)$ index.php?m=vod-search-pg-$1-wd-$2 break; rewrite ^/rss/(.*)/(.*)$ index.php?m=map-$1 break; rewrite ^/vod-list-id-(.*)-pg-(.*)-order-(.*)-by-(.*)-class-(.*)-year-(.*)-letter-(.*)-area-(.*)-lang-(.*)$ index.php?m=vod-list-id-$1-pg-$2-wd-$3-area-$4-lang-$5-year-$6-letter-$7-order-$8-by-$9 break;
web.config(IIS)
Windows IIS环境需要提前安装URL Rewrite模块,将xml内容写入站点根目录的web.config文件。
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule vodtype">
<match url="^type/(.*)-(.*)$" />
<action type="Rewrite" url="index.php?m=vod-type-id-{R:1}-pg-{R:2}" appendQueryString="false" />
</rule>
<rule name="Imported Rule voddetail">
<match url="^detail/(.*)$" />
<action type="Rewrite" url="index.php?m=vod-detail-id-{R:1}" appendQueryString="false" />
</rule>
<rule name="Imported Rule vodplay">
<match url="^play/(.*)-(.*)-(.*)$" />
<action type="Rewrite" url="index.php?m=vod-play-id-{R:1}-src-{R:2}-num-{R:3}" appendQueryString="false" />
</rule>
<rule name="Imported Rule voddown">
<match url="^down/(.*)-(.*)-(.*)$" />
<action type="Rewrite" url="index.php?m=vod-down-id-{R:1}-src-{R:2}-num-{R:3}" appendQueryString="false" />
</rule>
<rule name="Imported Rule vodsearch">
<match url="^search-pg-(.*)-wd-(.*)$" />
<action type="Rewrite" url="index.php?m=vod-search-pg-{R:1}-wd-{R:2}" appendQueryString="false" />
</rule>
<rule name="Imported Rule vodmap">
<match url="^map(.*)$" />
<action type="Rewrite" url="index.php?m=vod-map{R:1}" appendQueryString="false" />
</rule>
<rule name="Imported Rule shaixuan">
<match url="^vod-list-id-(.*)-pg-(.*)-order-(.*)-by-(.*)-class-(.*)-year-(.*)-letter-(.*)-area-(.*)-lang-(.*)$" />
<action type="Rewrite" url="index.php?m=vod-list-id-{R:1}-pg-{R:2}-wd-{R:3}-area-{R:4}-lang-{R:5}-year-{R:6}-letter-{R:7}-order-{R:8}-by-{R:9}" appendQueryString="false" />
</rule>
<rule name="Imported Rule ztlist">
<match url="^topiclist/(.*)-(.*)$" />
<action type="Rewrite" url="index.php?m=vod-topic-id-{R:1}-pg-{R:2}" appendQueryString="false" />
</rule>
<rule name="Imported Rule topic">
<match url="^topicindex(.*)$" />
<action type="Rewrite" url="index.php?m=vod-topicindex-pg-{R:1}" appendQueryString="false" />
</rule>
<rule name="Imported Rule artindex">
<match url="^artindex(.*)$" />
<action type="Rewrite" url="index.php?m=art-index-pg-{R:1}" appendQueryString="false" />
</rule>
<rule name="Imported Rule arttype">
<match url="^artlist/(.*)-(.*)$" />
<action type="Rewrite" url="index.php?m=art-type-id-{R:1}-pg-{R:2}" appendQueryString="false" />
</rule>
<rule name="Imported Rule artdetail">
<match url="^art/(.*)-(.*)$" />
<action type="Rewrite" url="index.php?m=art-detail-id-{R:1}-pg-{R:2}" appendQueryString="false" />
</rule>
<rule name="Imported Rule gbook">
<match url="^gbook/(.*)$" />
<action type="Rewrite" url="index.php?m=gbook-show-pg-{R:1}" appendQueryString="false" />
</rule>
<rule name="Imported Rule label">
<match url="^label/(.*)$" />
<action type="Rewrite" url="index.php?m=label-{R:1}" appendQueryString="false" />
</rule>
<rule name="Imported Rule artmap">
<match url="^artmap(.*)$" />
<action type="Rewrite" url="index.php?m=art-map{R:1}" appendQueryString="false" />
</rule>
<rule name="Imported Rule rss">
<match url="^rss/(.*)/(.*)$" />
<action type="Rewrite" url="index.php?m=map{R:1}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>苹果CMS V10伪静态配置注意事项
根据当前Web服务选择对应的规则文件,Nginx、Apache、IIS的配置不能互相混用。
站点部署在子目录时,修改路径参数,保证重写指向程序入口。
伪静态开启后,进入后台核对URL配置,和服务器重写规则保持一致。
修改规则文件后清空程序缓存,再逐个页面访问验证效果。
服务器内已有其他重写规则,需要调整规则顺序,避免Rewrite规则互相冲突。
修改配置前备份原有文件,出现404、500报错时可以快速回滚恢复。
如何测试伪静态是否生效?
保存配置之后,依次访问首页、分类页、播放页、搜索页、文章页面进行校验。页面正常加载,并且浏览器地址栏显示设定好的伪静态路径,代表规则生效。
访问报错时,优先排查服务器重写模块是否启用、配置文件存放位置、站点部署目录,以及程序内URL模板是否和重写规则匹配。
