Discuz论坛伪静态设置教程(X3.1和X3.2版本通用)
近日有BlueHost主机用户咨询小编关于Discuz论坛的伪静态设置问题。网站设置伪静态的好处想必大家都知道,那么像使用BlueHost这些虚拟主机空间的站长应该怎样设置呢?下面小编就给大家带来Discuz论坛伪静态设置的详细教程, X3.1和X3.2版本的DZ论坛都可适用。
如果你已经在虚拟主机空间上成功安装好Discuz论坛(BlueHost主机安装Discuz论坛教程),那就可以按照下面的方法开始设置:
- 开启论坛SEO伪静态。适用管理员账号登录到Discuz论坛后台,依次点击“全局”—“SEO设置”,在URL伪静态栏目下,勾选所有的URL为伪静态,如图所示:
- 访问下论坛上的页面看下伪静态有没有成功,如果没有接下来我们需要在添加伪静态规则。伪静态规则需要写在指定的文件中,然后上传到网站的根目录下。这里我们看下不同操作系统的虚拟主机应该如何写伪静态规则:
一般的Linux虚拟主机的伪静态规则:
将下面的代码复制到文件名为.htaccess的文件中保存,上传到Linux虚拟主机网站根目录下即可。
Apache Web Server(虚拟主机用户)
# 将 RewriteEngine 模式打开
RewriteEngine On
# 修改以下语句中的 /discuz 为您的论坛目录地址,如果程序放在根目录中,请将 /discuz 修改为 /
RewriteBase /discuz
# Rewrite 系统规则请勿修改
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^topic-(.+)\.html$ portal.php?mod=topic&topic=$1&%1
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^article-([0-9]+)-([0-9]+)\.html$ portal.php?mod=view&aid=$1&page=$2&%1
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^forum-(\w+)-([0-9]+)\.html$ forum.php?mod=forumdisplay&fid=$1&page=$2&%1
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ forum.php?mod=viewthread&tid=$1&extra=page\%3D$3&page=$2&%1
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^group-([0-9]+)-([0-9]+)\.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 ^archiver/(fid|tid)-([0-9]+)\.html$ archiver/index.php?action=$1&value=$2&%1
Windows虚拟主机的伪静态规则:
将下面的文件复制到文件名为httpd.ini文件中保存,上传到Windows虚拟主机的网站根目录下。
[ISAPI_Rewrite]
# 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-([0-9]+)-([0-9]+)\.html(\?(.*))*$ $1/portal\.php\?mod=view&aid=$2&page=$3&$5
RewriteRule ^(.*)/forum-(\w+)-([0-9]+)\.html(\?(.*))*$ $1/forum\.php\?mod=forumdisplay&fid=$2&page=$3&$5
RewriteRule ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html(\?(.*))*$ $1/forum\.php\?mod=viewthread&tid=$2&extra=page\%3D$4&page=$3&$6
RewriteRule ^(.*)/group-([0-9]+)-([0-9]+)\.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 ^(.*)/(fid|tid)-([0-9]+)\.html(\?(.*))*$ $1/index\.php\?action=$2&value=$3&$5
IIS7独立主机或者虚拟主机的写入规则:
将下面的代码复制到web.config文件下保存,然后上传到Windows主机的根目录下即可。
<?xml version=”1.0″ encoding=”UTF-8″?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name=”portal_topic”>
<match url=”^(.*/)*topic-(.+).html\?*(.*)[ DISCUZ_CODE_2 ]quot; />
<action type=”Rewrite” url=”{R:1}/portal.php\?mod=topic&topic={R:2}&{R:3}” />
</rule>
<rule name=”portal_article”>
<match url=”^(.*/)*article-([0-9]+)-([0-9]+).html\?*(.*)[ DISCUZ_CODE_2 ]quot; />
<action type=”Rewrite” url=”{R:1}/portal.php\?mod=view&aid={R:2}&page={R:3}&{R:4}” />
</rule>
<rule name=”forum_forumdisplay”>
<match url=”^(.*/)*forum-(\w+)-([0-9]+).html\?*(.*)[ DISCUZ_CODE_2 ]quot; />
<action type=”Rewrite” url=”{R:1}/forum.php\?mod=forumdisplay&fid={R:2}&page={R:3}&{R:4}” />
</rule>
<rule name=”forum_viewthread”>
<match url=”^(.*/)*thread-([0-9]+)-([0-9]+)-([0-9]+).html\?*(.*)[ DISCUZ_CODE_2 ]quot; />
<action type=”Rewrite” url=”{R:1}/forum.php\?mod=viewthread&tid={R:2}&extra=page%3D{R:4}&page={R:3}&{R:5}” />
</rule>
<rule name=”group_group”>
<match url=”^(.*/)*group-([0-9]+)-([0-9]+).html\?*(.*)[ DISCUZ_CODE_2 ]quot; />
<action type=”Rewrite” url=”{R:1}/forum.php\?mod=group&fid={R:2}&page={R:3}&{R:4}” />
</rule>
<rule name=”home_space”>
<match url=”^(.*/)*space-(username|uid)-(.+).html\?*(.*)[ DISCUZ_CODE_2 ]quot; />
<action type=”Rewrite” url=”{R:1}/home.php\?mod=space&{R:2}={R:3}&{R:4}” />
</rule>
<rule name=”forum_archiver”>
<match url=”^(.*/)*(fid|tid)-([0-9]+).html\?*(.*)[ DISCUZ_CODE_2 ]quot; />
<action type=”Rewrite” url=”{R:1}/index.php\?action={R:2}&value={R:3}&{R:4}” />
</rule>
</rules>
</rewrite>
<httpErrors errorMode=”DetailedLocalOnly”>
<remove statusCode=”404″ />
<error statusCode=”404″ path=”/404.htm” responseMode=”ExecuteURL” />
</httpErrors>
</system.webServer>
<system.web>
<customErrors mode=”Off” />
<globalization requestEncoding=”utf-8″ responseEncoding=”utf-8″ fileEncoding=”utf-8″ />
</system.web>
</configuration>
一般只要通过以上两个步骤,Discuz论坛伪静态就设置成功了。不过,前提你的主机要支持伪静态才行!