前言, 最近一直遇到这样的问题:

每次都只在电脑中的某个浏览器随手收藏喜欢的网站,后面再找就得每台电脑,每个浏览器都打开来翻个底朝天,非常浪费时间。就想着能不能自己整个分类目录网站,把网址提交上去,有空就往上加,以后就不用这么麻烦的找了。而刚好手上有闲着的空间和玉米,就去找了相关的主题。

本来有个不错的源码是 卢松松还没做大时放出的《博客大全源码》,可惜源码结构是ASP+ACCESS架构的,这个环境本人是0研究,也懒得再去从头学起了。只能找些PHP+MYSQL的源码,于是就找到了这个帝《帝国CMS7.2大前端模板分类目录源码整站程序》,刚好听说过帝国,是个不错的CMS,就选这个了。

废话不说,直接进入正题,按源码的使用的方法安装好,恢复数据后,发现网站大部份的链接都是404,一看就知道是伪静态的问题,虽然没接触过这个CMS,但基本原理都一样的。

具体步骤如下

1.先确定本空间所使用的环境(是apache还是nginx),以确定修改的文件。本VPS是装的LNMP,所以是nginx。因此配置的文件应该是.conf(如果是apache,也就是LAMP, 配置的是.htaccess文件)。

2.找到相关的帝国CMS7.2伪静态代码,这里只找到apache的写法:

 

# 将 RewriteEngine 模式打开 
RewriteEngine On 
#信息内容页:showinfo-[!--classid--]-[!--id--]-[!--page--].html 
RewriteCond %{QUERY_STRING} ^(.*)$ 
RewriteRule ^showinfo-(.+?)-(.+?)-(.+?)\.html$ /e/action/ShowInfo\.php\?classid=$1&id=$2&page=$3

#信息列表:listinfo-[!--classid--]-[!--page--].html 
RewriteCond %{QUERY_STRING} ^(.*)$ 
RewriteRule ^listinfo-(.+?)-(.+?)\.html$ /e/action/ListInfo/index.php?classid=$1&page=$2

#标题分类列表页:infotype-[!--ttid--]-[!--page--].html 
RewriteCond %{QUERY_STRING} ^(.*)$ 
RewriteRule ^infotype-(.+?)-(.+?)\.html$ /e/action/InfoType/index.php?ttid=$1&page=$2

#TAGS信息列表页:tags-[!--tagname--]-[!--page--].html 
RewriteCond %{QUERY_STRING} ^(.*)$ 
RewriteRule ^tags-(.+?)-(.+?)\.html$ /e/tags/index.php?tagname=$1&page=$2

# 首页、分类浏览、数据归档、最近更新、排行榜、意见反馈 
RewriteRule ^(index¦webdir¦weblink¦article¦category¦update¦archives¦top¦feedback¦link¦rssfeed¦sitemap)(\.html)$ index.php\?mod=$1&%1 
RewriteRule ^(index¦webdir¦weblink¦article¦category¦update¦archives¦top¦feedback¦link¦rssfeed¦sitemap)(\/?)$ index.php\?mod=$1 
# 最近更新 
RewriteRule ^update-(\d+)-(\d+)\.html$ index.php\?mod=update&days=$1&page=$2 
RewriteRule ^update\/(\d+)-(\d+)\.html$ index.php\?mod=update&days=$1&page=$2 
RewriteRule ^update\/(\d+)/(\d+)$ index.php\?mod=update&days=$1&page=$2

# 数据归档 
RewriteRule ^archives-(\d+)-(\d+)\.html$ index.php\?mod=archives&date=$1&page=$2 
RewriteRule ^archives\/(\d+)-(\d+)\.html$ index.php\?mod=archives&date=$1&page=$2 
RewriteRule ^archives\/(\d+)/(\d+)$ index.php\?mod=archives&date=$1&page=$2

# 站内搜索 
RewriteRule ^search-(name¦url¦tags¦baidu¦intro¦br¦pr¦sr)-(.*)-(\d+)\.html$  index.php\?mod=search&type=$1&query=$2&page=$3 
RewriteRule ^search-(name¦url¦tags¦baidu¦intro¦br¦pr¦sr)-(.*)\.html$  index.php\?mod=search&type=$1&query=$2

# 站内搜索 
RewriteRule ^search-(name¦url¦tags¦baidu¦intro¦br¦pr¦sr)-(.*)-(\d+)\.html$  index.php\?mod=search&type=tags&query=$2 
RewriteRule ^search-(name¦url¦tags¦baidu¦intro¦br¦pr¦sr)-(.*)-(\d+)\.html$  index.php\?mod=search&type=$1&query=$1 
RewriteRule ^search-(name¦url¦tags¦baidu¦intro¦br¦pr¦sr)-(.*)\.html$  index.php\?mod=search&type=$1&query=$2

RewriteRule ^search\/(name¦url¦tags¦baidu¦intro¦br¦pr¦sr)\/(.*)-(\d+)\.html$  index.php\?mod=search&type=$1&query=$2&page=$3 
RewriteRule ^search\/(name¦url¦tags¦baidu¦intro¦br¦pr¦sr)\/(.*)\.html$  index.php\?mod=search&type=$1&query=$2

RewriteRule ^search\/(name¦url¦tags¦baidu¦intro¦br¦pr¦sr)\/(.+)/(\d+)$ index.php\?mod=search&type=$1&query=$2&page=$3 
RewriteRule ^search\/(name¦url¦tags¦baidu¦intro¦br¦pr¦sr)\/(.+)$ index.php\?mod=search&type=$1&query=$2

RewriteRule ^/search\/(name¦url¦tags¦intro¦br¦pr¦sr)\/(.+)-(\d+)\.html$ /index.php\?mod=search&type=$1&query=$2&page=$3 
RewriteRule ^/search\/(name¦url¦tags¦intro¦br¦pr¦sr)\/(.+)\.html$ /index.php\?mod=search&type=$1&query=$2


# 站点详细 
RewriteRule ^siteinfo-(\d+)\.html$ index.php\?mod=siteinfo&wid=$1 
RewriteRule ^siteinfo\/(\d+)\.html$ index.php\?mod=siteinfo&wid=$1 
RewriteRule ^siteinfo\/(\d+)$ index.php\?mod=siteinfo&wid=$1

# 文章详细 
RewriteRule ^artinfo-(\d+)\.html$ index.php\?mod=artinfo&aid=$1 
RewriteRule ^artinfo\/(\d+)\.html$ index.php\?mod=artinfo&aid=$1 
RewriteRule ^artinfo\/(\d+)$ index.php\?mod=artinfo&aid=$1

# 链接详细 
RewriteRule ^linkinfo-(\d+)\.html$ index.php\?mod=linkinfo&lid=$1 
RewriteRule ^linkinfo\/(\d+)\.html$ index.php\?mod=linkinfo&lid=$1 
RewriteRule ^linkinfo\/(\d+)$ index.php\?mod=linkinfo&lid=$1

# 单页 
RewriteRule ^diypage-(\d+)\.html$ index.php\?mod=diypage&pid=$1 
RewriteRule ^diypage\/(\d+)\.html$ index.php\?mod=diypage&pid=$1 
RewriteRule ^diypage\/(\d+)$ index.php\?mod=diypage&pid=$1

# RSS 
RewriteRule ^rssfeed-(.+)-(\d+)\.html$ index.php\?mod=rssfeed&type=$1&cid=$2 
RewriteRule ^rssfeed-(.+)\.html$ index.php\?mod=rssfeed&type=$1&cid=$2

RewriteRule ^rssfeed\/(.+)/$ index.php\?mod=rssfeed&type=$1 
RewriteRule ^rssfeed\/(.+)/(\d+)\.html$ index.php\?mod=rssfeed&type=$1&cid=$2

RewriteRule ^rssfeed\/(.+)$ index.php\?mod=rssfeed&type=$1 
RewriteRule ^rssfeed\/(.+)/(\d+)$ index.php\?mod=rssfeed&type=$1&cid=$2

# SiteMap 
RewriteRule ^sitemap-(.+)\.html$ index.php\?mod=sitemap&cid=$1 
RewriteRule ^sitemap\/(\d+)\/$ index.php\?mod=sitemap&cid=$1 
RewriteRule ^sitemap\/(\d+)$ index.php\?mod=sitemap&cid=$1

# 分类目录 
RewriteRule ^webdir-(.+)-(\d+)-(\d+)\.html$ index.php\?mod=webdir&cid=$2&page=$3 
RewriteRule ^webdir\/(.+)\/(\d+)-(\d+)\.html$ index.php\?mod=webdir&cid=$2&page=$3 
RewriteRule ^webdir\/(.+)\/(\d+)/(\d+)$ index.php\?mod=webdir&cid=$2&page=$3

RewriteRule ^article-(.+)-(\d+)-(\d+)\.html$ index.php\?mod=article&cid=$2&page=$3 
RewriteRule ^article\/(.+)\/(\d+)-(\d+)\.html$ index.php\?mod=article&cid=$2&page=$3 
RewriteRule ^article\/(.+)\/(\d+)/(\d+)$ index.php\?mod=article&cid=$2&page=$3

# END

 

要改成nginx的写法,转换如下:

nginx 伪静态规则 ( 请自行测试)

rewrite ^/(index¦article¦webdir¦category¦update¦archives¦top¦feedback¦weblink¦rssfeed¦sitemap)(/?)$ /index.php?mod=$1 last;
rewrite ^/update/(\d+).html$ /index.php?mod=update&days=$1 last;
rewrite ^/update/(\d+)-(\d+).html$ /index.php?mod=update&days=$1&page=$2 last;
rewrite ^/archives/(\d+).html$ /index.php?mod=archives&date=$1 last;
rewrite ^/archives/(\d+)-(\d+).html$ /index.php?mod=archives&date=$1&page=$2 last;
rewrite ^/webdir/(.*)/(\d+)-1.html$ /index.php?mod=webdir&cid=$2 last;
rewrite ^/webdir/(.*)/(\d+)-(\d+).html$ /index.php?mod=webdir&cid=$2&page=$3 last;
rewrite ^/search/(name¦url¦tags¦intro¦pr¦br)/(.+)-(\d+).html$ /index.php?mod=search&type=$1&query=$2&page=$3 last;
rewrite ^/search/(name¦url¦tags¦intro¦pr¦br)/(.+).html$ /index.php?mod=search&type=$1&query=$2 last;
rewrite ^/siteinfo/(\d+).html$ /index.php?mod=siteinfo&wid=$1 last;
rewrite ^/artinfo/(\d+).html$ /index.php?mod=artinfo&aid=$1 last;
rewrite ^/linkinfo/(\d+).html$ /index.php?mod=linkinfo&lid=$1 last;
rewrite ^/diypage/(\d+).html$ /index.php?mod=diypage&pid=$1 last;
rewrite ^/rssfeed/(\d+).html$ /index.php?mod=rssfeed&cid=$1 last;
rewrite ^/sitemap/(\d+).html$ /index.php?mod=sitemap&cid=$1 last;
rewrite ^/(.+)/(\d+)-(\d+).html$ /index.php?mod=directory&cid=$2&page=$3 last;
rewrite ^/article/(.*)/(\d+)-1.html$ /index.php?mod=article&cid=$2 last;
rewrite ^/article/(.*)/(\d+)-(\d+).html$ /index.php?mod=article&cid$2&page=$3 last;
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;
}

 

3.修改对应网站的conf文件,对于军哥的LNMP环境来说,位置如下 :/usr/local/nginx/conf/vhost

解决 Lnmp环境中 为帝国cms7.2 开启伪静态的问题

打开可以看到,这里引用的是哪个cms的conf以及其所在位置:/usr/local/nginx/conf

解决 Lnmp环境中 为帝国cms7.2 开启伪静态的问题

可以看到,这里引用的是wordpress.conf,于是自己在:/usr/local/nginx/conf添加一个帝国专用的conf, 新建diguocms.conf,并把上面的代码添加进去保存。

解决 Lnmp环境中 为帝国cms7.2 开启伪静态的问题

最后在 url.conf修改引入的conf文件即可,如下图:

解决 Lnmp环境中 为帝国cms7.2 开启伪静态的问题

4.重启服务:lnmp restart. 搞定。