帝国CMS在不同环境中伪静态规则的写法

帝国CMS的伪静态规则,也就是针对动态网页URL,比如列表动态页面、文章内容动态页面、搜索页面、评论页面、Tags标签页面进行的链接优化,有助于网站在url链接的权重提升,如果我们使用的轻量应用服务器,安装宝塔面板之后,可以很方便的设置伪静态规则,可是对于虚拟主机用户,设置伪静态规则就不是那么简单了,分享出一段代码,希望能够帮助到使用虚拟主机构建帝国CMS网站的朋友实现伪静态。那么如何设置帝国cms的伪静态规则呢

Apache下的.htaccess

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
RewriteEngine On
Rewritebase /
#信息内容页
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^showinfo-([0-9]+)-([0-9]+)-([0-9]+).html$ /e/action/ShowInfo.php?classid=$1&id=$2&page=$3 [NC,L]
#信息列表
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^listinfo-([0-9]+)-([0-9]+).html$ /e/action/ListInfo/index.php?classid=$1&page=$2 [NC,L]
#标题分类列表页
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^infotype-([0-9]+)-([0-9]+).html$ /e/action/InfoType/index.php?ttid=$1&page=$2 [NC,L]
#TAGS信息列表页
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^tags-(.+?)-([0-9]+).html$ /e/tags/index.php?tagname=$1&page=$2 [NC,L]
#评论列表页
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^comment-([0-9]+)-([0-9]+)-([0-9]+)-([0-9]+)-([0-9]+)-([0-9]+).html$ /e/pl/index.php?doaction=$1&classid=$2&id=$3&page=$4&myorder=$5&tempid=$6 [NC,L]

找到的另一种代码方式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
RewriteEngine On
ErrorDocument 404 /404.html
Rewritebase /
#信息列表
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^listinfo-(.+?)-(.+?)/.html$ /e/action/ListInfo/index/.php/?classid=$1&page=$2
#信息内容页
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^showinfo-(.+?)-(.+?)-(.+?)/.html$ /e/action/ShowInfo/.php/?classid=$1&id=$2&page=$3
#标题分类列表页
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^infotype-(.+?)-(.+?)/.html$ /e/action/InfoType/index/.php/?ttid=$1&page=$2
#TAGS信息列表页
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^tags-(.+?)-(.+?)/.html$ /e/tags/index/.php/?tagname=$1&page=$2
#评论列表页
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^comment-(.+?)-(.+?)-(.+?)-(.+?)-(.+?)-(.+?)/.html$ /e/pl/index/.php/?doaction=$1&classid=$2&id=$3&page=$4&myorder=$5&tempid=$6

时间关系,我没有虚拟主机环境,也不懂的伪静态的规则,不知道上面那段代码可以实现,算是做一个简单的记录。

Nginx下伪静态

1
2
3
4
5
6
7
8
rewrite ^([^.]*)/listinfo-(.+?)-(.+?).html$ $1/e/action/ListInfo/index.php?classid=$2&page=$3 last;
rewrite ^([^.]*)/showinfo-(.+?)-(.+?)-(.+?).html$ $1/e/action/ShowInfo.php?classid=$2&id=$3&page=$4 last;
rewrite ^([^.]*)/infotype-(.+?)-(.+?).html$ $1/e/action/InfoType/index.php?ttid=$2&page=$3 last;
rewrite ^([^.]*)/tags-(.+?)-(.+?).html$ $1/e/tags/index.php?tagname=$2&page=$3 last;
rewrite ^([^.]*)/comment-(.+?)-(.+?)-(.+?)-(.+?)-(.+?)-(.+?).html$ $1/e/pl/index.php?doaction=$2&classid=$3&id=$4&page=$5&myorder=$6&tempid=$7 last;
if (!-e $request_filename) {
return 404;
}

需要注意一个问题,从帝国CMS7.5起,支持Tagsid功能,也就是以前的tagname改成了tagid,让更喜欢id风格的网友满意了,如果你使用tagid,那么你的伪静态规则需要做以下修改

1
rewrite ^([^\.]*)/tags-(.+?)-(.+?)\.html$ $1/e/tags/index.php?tagname=$2&page=$3 last;

修改为

1
rewrite ^([^\.]*)/tags-(.+?)-(.+?)\.html$ $1/e/tags/index.php?tagid=$2&page=$3 last;

最后将修改好的伪静态规则保存到服务器,然后就可以看到我们希望的效果了。

IIS6下的httpd.ini

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[ISAPI_Rewrite]
# 3600 = 1 hour
CacheClockRate 3600
RepeatLimit 32
#信息列表
RewriteRule ^(.*)listinfo-(.+?)-(.+?).html$ $1/e/action/ListInfo/index.php?classid=$2&page=$3
#信息内容页
RewriteRule ^(.*)showinfo-(.+?)-(.+?)-(.+?).html$ $1/e/action/ShowInfo.php?classid=$2&id=$3&page=$4
#标题分类列表页
RewriteRule ^(.*)infotype-(.+?)-(.+?).html$ $1/e/action/InfoType/index.php?ttid=$2&page=$3
#TAGS信息列表页
RewriteRule ^(.*)tags-(.+?)-(.+?).html$ $1/e/tags/index.php?tagname=$2&page=$3
#评论列表页
RewriteRule ^(.*)comment-(.+?)-(.+?)-(.+?)-(.+?)-(.+?)-(.+?).html$ $1/e/pl/index.php?doaction=$2&classid=$3&id=$4&page=$5&myorder=$6&tempid=$7

这种设置帝国CMS伪静态的规则比较少,虚拟主机的httpd.ini一般不对外开放,也就是虚拟主机的使用者一般接触不到这个文件,详情需要联系虚拟主机商。

IIS7下的web.config

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<!--帝国7.5默认规则 IIS7的rule name不能重复相同-->
<rewrite>
<rules>
<rule name="listinfo">
<match url="^(.*/)*listinfo-(.+?)-(.+?).html?*(.*)$" />
<action type="Rewrite" url="{R:1}/e/action/ListInfo/index.php?classid={R:2}&amp;page={R:3}" />
</rule>
<rule name="showinfo">
<match url="^(.*/)*showinfo-(.+?)-(.+?)-(.+?).html?*(.*)$" />
<action type="Rewrite" url="{R:1}/e/action/ShowInfo.php?classid={R:2}&amp;id={R:3}&amp;page={R:4}" />
</rule>
<rule name="infotype">
<match url="^(.*/)*infotype-(.+?)-(.+?).html?*(.*)$" />
<action type="Rewrite" url="{R:1}/e/action/InfoType/index.php?ttid={R:2}&amp;page={R:3}" />
</rule>
<rule name="tags">
<match url="^(.*/)*tags-(.+?)-(.+?).html?*(.*)$" />
<action type="Rewrite" url="{R:1}/e/tags/index.php?tagname={R:2}&amp;page={R:3}" />
</rule>
<rule name="comment">
<match url="^(.*/)*comment-(.+?)-(.+?)-(.+?)-(.+?)-(.+?)-(.+?).html?*(.*)$" />
<action type="Rewrite" url="{R:1}/e/pl/index.php?doaction={R:2}&amp;={R:3}&amp;={R:4}&amp;page={R:5}&amp;myorder={R:6}&amp;tempid={R:7}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

这种方法还是使用的比较过,例如zblog在Windows+iis情况下的一键伪静态设置,就是在网站的根目录下面创建这个web.config文件,文件之中对应的就是zblog需要的伪静态规则,但是帝国CMS没有这种功能,只能是依靠自己来在虚拟主机中网站的根目录下面自己来创建这个web.config文件,然后将上面的伪静态规则代码添加进去。最后,至于搜索页的伪静态规则,有专门的设置方法,大家可以在网站上找一找!后续问题,会持续更新,有好的建议,大家也可以分享给我。