admin 发表于 2018-2-28 03:02:28

Discuz!系列教程-通过判断空间类型选择伪静态方式

程序版本:Discuz!x1.5-x3.1
目的:给新手认清空间类型,从而选择合适的伪静态方式
适合人群:使用Discuz!x1.5-x3.1的站长

具体内容:
1.后台,登录,首页会看到这样的一张图:
http://www.discuz.net/data/attachment/forum/201301/06/014433p3ilxmyailiooooy.png.thumb.jpg
2.仔细看这内容:

服务器系统及 PHP、服务器软件

可能的组合有:
(1)服务器系统及 PHP:WINNT / PHP v5.X.X服务器软件:Microsoft-IIS/6.0
这时候选择的伪静态规则对应的是:IIS Web Server(独立主机用户)


# 3600 = 1 hour
CacheClockRate 3600

RepeatLimit 32

# Protect httpd.ini and httpd.parse.errors files
# from accessing through HTTP
RewriteRule ^(.*)/topic-(.+)\.html(\?(.*))*$ $1/portal\.php\?mod=topic&topic=$2&$4
RewriteRule ^(.*)/article-(+)-(+)\.html(\?(.*))*$ $1/portal\.php\?mod=view&aid=$2&page=$3&$5
RewriteRule ^(.*)/forum-(\w+)-(+)\.html(\?(.*))*$ $1/forum\.php\?mod=forumdisplay&fid=$2&page=$3&$5
RewriteRule ^(.*)/thread-(+)-(+)-(+)\.html(\?(.*))*$ $1/forum\.php\?mod=viewthread&tid=$2&extra=page\%3D$4&page=$3&$6
RewriteRule ^(.*)/group-(+)-(+)\.html(\?(.*))*$ $1/forum\.php\?mod=group&fid=$2&page=$3&$5
RewriteRule ^(.*)/space-(username|uid)-(.+)\.html(\?(.*))*$ $1/home\.php\?mod=space&$2=$3&$5
RewriteRule ^(.*)/blog-(+)-(+)\.html(\?(.*))*$ $1/home\.php\?mod=space&uid=$2&do=blog&id=$3&$5
RewriteRule ^(.*)/(fid|tid)-(+)\.html(\?(.*))*$ $1/index\.php\?action=$2&value=$3&$5
RewriteRule ^(.*)/(+*)-(+)\.html(\?(.*))*$ $1/plugin\.php\?id=$2:$3&$5
将以上内容保存为httpd.ini 上传到网站根目录
(2)服务器系统及 PHP:WINNT / PHP v5.2.16服务器软件:Microsoft-IIS/7.X
这时候选择的伪静态规则对应的是:IIS7 Web Server(独立主机用户)
规则文件:



备注:对应虚拟空间的用户上传这个规则就可以了,如果空间商有自定义规则方式需要和空间商客服核实下(万网是自定义规则)或者可以QQ咨询。如果是独立主机涉及到伪静态组件设置,就不在这里另外说明了。

(3)服务器系统及 PHP : Linux / PHP v5.X.X服务器软件:Apache
这时候选择的伪静态规则对应的是:Apache Web Server(虚拟主机用户)
# 将 RewriteEngine 模式打开
RewriteEngine On

# 修改以下语句中的 /discuz 为您的论坛目录地址,如果程序放在根目录中,请将 /discuz 修改为 /
RewriteBase /

# Rewrite 系统规则请勿修改
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^topic-(.+)\.html$ portal.php?mod=topic&topic=$1&%1
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^article-(+)-(+)\.html$ portal.php?mod=view&aid=$1&page=$2&%1
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^forum-(\w+)-(+)\.html$ forum.php?mod=forumdisplay&fid=$1&page=$2&%1
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^thread-(+)-(+)-(+)\.html$ forum.php?mod=viewthread&tid=$1&extra=page\%3D$3&page=$2&%1
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^group-(+)-(+)\.html$ forum.php?mod=group&fid=$1&page=$2&%1
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^space-(username|uid)-(.+)\.html$ home.php?mod=space&$1=$2&%1
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^blog-(+)-(+)\.html$ home.php?mod=space&uid=$1&do=blog&id=$2&%1
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^archiver/(fid|tid)-(+)\.html$ archiver/index.php?action=$1&value=$2&%1
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^(+*)-(+)\.html$ plugin.php?id=$1:$2&%1
以上规则具体如何使用见http://service.iitt.cc/thread-4804-1-1.html

这时候会有人有疑问了:如果是独立Linux服务器用什么规则?

如果是独立主机会有独立的httpd-vhosts.conf配置文件,可以在这个文件的网站配置字段中加入:
<IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteCond %{QUERY_STRING} ^(.*)$
      RewriteRule ^(.*)/topic-(.+)\.html$ $1/portal.php?mod=topic&topic=$2&%1
      RewriteCond %{QUERY_STRING} ^(.*)$
      RewriteRule ^(.*)/article-(+)-(+)\.html$ $1/portal.php?mod=view&aid=$2&page=$3&%1
      RewriteCond %{QUERY_STRING} ^(.*)$
      RewriteRule ^(.*)/forum-(\w+)-(+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3&%1
      RewriteCond %{QUERY_STRING} ^(.*)$
      RewriteRule ^(.*)/thread-(+)-(+)-(+)\.html$ $1/forum.php?mod=viewthread&tid=$2&extra=page\%3D$4&page=$3&%1
      RewriteCond %{QUERY_STRING} ^(.*)$
      RewriteRule ^(.*)/group-(+)-(+)\.html$ $1/forum.php?mod=group&fid=$2&page=$3&%1
      RewriteCond %{QUERY_STRING} ^(.*)$
      RewriteRule ^(.*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space&$2=$3&%1
      RewriteCond %{QUERY_STRING} ^(.*)$
      RewriteRule ^(.*)/blog-(+)-(+)\.html$ $1/home.php?mod=space&uid=$2&do=blog&id=$3&%1
      RewriteCond %{QUERY_STRING} ^(.*)$
      RewriteRule ^(.*)/(fid|tid)-(+)\.html$ $1/index.php?action=$2&value=$3&%1
      RewriteCond %{QUERY_STRING} ^(.*)$
      RewriteRule ^(.*)/(+*)-(+)\.html$ $1/plugin.php?id=$2:$3&%1
</IfModule>
这些规则内容。
一个案例:
<VirtualHost *:80>
DocumentRoot /home/xmspace
ServerName www.xmspace.net
<IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteCond %{QUERY_STRING} ^(.*)$
      RewriteRule ^(.*)/topic-(.+)\.html$ $1/portal.php?mod=topic&topic=$2&%1
      RewriteCond %{QUERY_STRING} ^(.*)$
      RewriteRule ^(.*)/article-(+)-(+)\.html$ $1/portal.php?mod=view&aid=$2&page=$3&%1
      RewriteCond %{QUERY_STRING} ^(.*)$
      RewriteRule ^(.*)/forum-(\w+)-(+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3&%1
      RewriteCond %{QUERY_STRING} ^(.*)$
      RewriteRule ^(.*)/thread-(+)-(+)-(+)\.html$ $1/forum.php?mod=viewthread&tid=$2&extra=page\%3D$4&page=$3&%1
      RewriteCond %{QUERY_STRING} ^(.*)$
      RewriteRule ^(.*)/group-(+)-(+)\.html$ $1/forum.php?mod=group&fid=$2&page=$3&%1
      RewriteCond %{QUERY_STRING} ^(.*)$
      RewriteRule ^(.*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space&$2=$3&%1
      RewriteCond %{QUERY_STRING} ^(.*)$
      RewriteRule ^(.*)/blog-(+)-(+)\.html$ $1/home.php?mod=space&uid=$2&do=blog&id=$3&%1
      RewriteCond %{QUERY_STRING} ^(.*)$
      RewriteRule ^(.*)/(fid|tid)-(+)\.html$ $1/index.php?action=$2&value=$3&%1
      RewriteCond %{QUERY_STRING} ^(.*)$
      RewriteRule ^(.*)/(+*)-(+)\.html$ $1/plugin.php?id=$2:$3&%1
</IfModule>
</VirtualHost>
(4)服务器系统及 PHP : Linux / PHP v5.X.X服务器软件:Nginx
这时候选择的伪静态规则对应的是:Nginx Web Server
如果选择的是独立服务器下面给一个案例:

vi /usr/local/nginx/conf/nginx.conf #编辑nginx配置文件
找到下面这行,在server_name localhost;后边一行添加上面的代码
server {
listen 80;
server_name localhost;
rewrite ^([^\.]*)/topic-(.+)\.html$ $1/portal.php?mod=topic&topic=$2 last;
rewrite ^([^\.]*)/article-(+)-(+)\.html$ $1/portal.php?mod=view&aid=$2&page=$3 last;
rewrite ^([^\.]*)/forum-(\w+)-(+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3 last;
rewrite ^([^\.]*)/thread-(+)-(+)-(+)\.html$ $1/forum.php?mod=viewthread&tid=$2&extra=page%3D$4&page=$3 last;
rewrite ^([^\.]*)/group-(+)-(+)\.html$ $1/forum.php?mod=group&fid=$2&page=$3 last;
rewrite ^([^\.]*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space&$2=$3 last;
rewrite ^([^\.]*)/blog-(+)-(+)\.html$ $1/home.php?mod=space&uid=$2&do=blog&id=$3 last;
rewrite ^([^\.]*)/(fid|tid)-(+)\.html$ $1/index.php?action=$2&value=$3 last;
rewrite ^([^\.]*)/(+*)-(+)\.html$ $1/plugin.php?id=$2:$3 last;
if (!-e $request_filename) {
      return 404;
}

#access_log logs/host.access.log main;
location / {
root html;
index index.php index.html index.htm;
}
如果是虚拟主机一般支持.htaccess

直接将:rewrite ^([^\.]*)/topic-(.+)\.html$ $1/portal.php?mod=topic&topic=$2 last;
rewrite ^([^\.]*)/article-(+)-(+)\.html$ $1/portal.php?mod=view&aid=$2&page=$3 last;
rewrite ^([^\.]*)/forum-(\w+)-(+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3 last;
rewrite ^([^\.]*)/thread-(+)-(+)-(+)\.html$ $1/forum.php?mod=viewthread&tid=$2&extra=page%3D$4&page=$3 last;
rewrite ^([^\.]*)/group-(+)-(+)\.html$ $1/forum.php?mod=group&fid=$2&page=$3 last;
rewrite ^([^\.]*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space&$2=$3 last;
rewrite ^([^\.]*)/blog-(+)-(+)\.html$ $1/home.php?mod=space&uid=$2&do=blog&id=$3 last;
rewrite ^([^\.]*)/(fid|tid)-(+)\.html$ $1/index.php?action=$2&value=$3 last;
rewrite ^([^\.]*)/(+*)-(+)\.html$ $1/plugin.php?id=$2:$3 last;
if (!-e $request_filename) {
      return 404;
}保存为.htaccess上传网站根目录,再测试是否成功,由于各家空间商的规则设置方式不同,有些使用的是自己的后台空间管理界面设置,所以在使用时还是咨询下空间商客服。

最后一种是Zeus Web Server模式,这个由于使用相对较少,如遇到可以直接咨询空间商或QQ我

以上就是如果给新手用于判断空间类型,选择合适伪静态教程。

页: [1]
查看完整版本: Discuz!系列教程-通过判断空间类型选择伪静态方式