对于熟悉apache配置的童鞋这可能是个简单的问题,但是我总是记不住,因此略记一下,以备不时之需。下面的所有配置都是针对我的博客地址rockins.cn而作的。

首先是在httpd.conf中要增加下面几行,也就是允许每个virtual host目录下的.htaccess覆盖httpd.conf中的配置:
<Directory /var/www/htdocs/rockins.cn/>
AllowOverride all
Order allow,deny
Allow from all
</Directory>

然后,在httpd-vhosts.conf中,增加一个virtual host项:

<VirtualHost *:80>

ServerAdmin ybc2084@gmail.com
DocumentRoot “/var/www/htdocs/rockins.cn/”
ServerName rockins.cn
ServerAlias blog.rockins.cn www.rockins.cn
ErrorLog “logs/rockins.cn-error_log”
CustomLog “logs/rockins.cn-access_log” common
</VirtualHost>

最后,在/var/www/htdocs/rockins.cn/目录下,新建一个.htaccess文件,输入如下内容:

自此一切OK,收工。

原文


Apache 2.x 的用户请检查 conf/httpd.conf 中是否存在如下一段代码:

 

LoadModule Rewrite_module modules/mod_Rewrite.so

如果存在,那么在配置文件(通常就是 conf/httpd.conf)中加入如下代码。此时请务必注意,如果网站使用通过虚拟主机来定义,请务必加到虚拟主机配置,即 <VirtualHost> 中去,如果加在虚拟主机配置外部将可能无法使用,改好后将 Apache 重启。

<IfModule mod_Rewrite.c>
RewriteEngine On
RewriteRule ^(.*)/archiver/((fid|tid)-[w-]+.html)$ $1/archiver/index.php?$2
RewriteRule ^(.*)/forum-([0-9]+)-([0-9]+).html$ $1/forumdisplay.php?fid=$2&page=$3
RewriteRule ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+).html$ $1/viewthread.php?tid=$2&extra=page%3D$4&page=$3
RewriteRule ^(.*)/space-(username|uid)-(.+).html$ $1/space.php?$2=$3
RewriteRule ^(.*)/tag-(.+).html$ $1/tag.php?name=$2
</IfModule>

如果没有安装 mod_Rewrite,您可以重新编译 Apache,并在原有 configure 的内容中加入 –enable-Rewrite=shared,然后再在 Apache 配置文件中加入上述代码即可。

另外一种用户是 Apache 虚拟主机用户。

在开始以下设置之前,请首先咨询您的空间服务商,空间是否支持 Rewrite 以及是否支持对站点目录中 .htaccess 的文件解析,否则即便按照下面的方法设置好了,也无法使用。

检查论坛所在目录中是否存在 .htaccess 文件,如果不存在,请手工建立此文件。Win32 系统下,无法直接建立 .htaccess 文件,您可以从其他系统中拷贝一份,或者在 Discuz.net 技术支持栏目中下载此文件。编辑并修改 .htaccess 文件,添加以下内容:

# 将 RewriteEngine 模式打开
RewriteEngine On
# 修改以下语句中的 /discuz 为你的论坛目录地址,如果程序放在根目录中,请将 /discuz 修改为 /
RewriteBase /discuz
# Rewrite 系统规则请勿修改
RewriteRule ^archiver/((fid|tid)-[w-]+.html)$ archiver/index.php?$1
RewriteRule ^forum-([0-9]+)-([0-9]+).html$ forumdisplay.php?fid=$1&page=$2
RewriteRule ^thread-([0-9]+)-([0-9]+)-([0-9]+).html$ viewthread.php?tid=$1&extra=page%3D$3&page=$2
RewriteRule ^space-(username|uid)-(.+).html$ space.php?$1=$2
RewriteRule ^tag-(.+).html$ tag.php?name=$1

添加内容时,请遵照上面的提示,修改论坛所在的路径,然后保存。将 .htaccess 文件上传到论坛所在的目录中。然后进入论坛系统设置的搜索引擎优化,根据需要开启 URL 静态化功能。

原文

发表评论

电子邮件地址不会被公开。

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

4849125181773634231615112522351438332839842132610194533024144474020293792131274506324324146