如何配置apache rewrite规则呢,无论是linux主机还是windows主机都是大同小异的。
现在我们以WAMP服务器为例子,讲解两个站点并存,且一个站点做rewrite的配置。
主要修改两个文件
1)
httpd.conf
C:\wamp\bin\apache\Apache2.2.21\conf
2) httpd-vhosts.conf
C:\wamp\bin\apache\Apache2.2.21\conf\extra
修改重点如下
1)httpd.conf
LoadModule rewrite_module modules/mod_rewrite.so
将前面的#去除
表明打开Rewrite功能
注意在wamp中部分参数已经默认设定,会对rewrite产生影响,列出如下
DocumentRoot "c:/wamp/www/"
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory> 此处表示wamp站点的默认设置红色部分对rewrite有影响
————————————————————————————————————————————
<Directory
"c:/wamp/www/">
Options
None
表明此目录下所有虚拟站点禁止目录列表
AllowOverride
all
rewrite必须打开,也可以在这里关闭,在
httpd-vhosts.conf 打开
Order
Allow,Deny
Allow from
all rewrite必须打开,也可以在这里关闭,在
httpd-vhosts.conf 打开
</Directory>
————————————————————————————————————————————
2)
httpd-vhosts.conf
修改如下
<VirtualHost
*:80>
此虚拟站点不支持rewrite,因为默认Options
None
ServerAdmin
webmaster@dummy-host.example.com
DocumentRoot
"c:/wamp/www/lm/"
ServerName
www.xxx.com
ErrorLog
"logs/www.xxx.com-error.log"
CustomLog
"logs/www.xxx.com-access.log" common
</VirtualHost>
<VirtualHost *:80>
此虚拟站点支持rewrite,因为Options Indexes
FollowSymLinks
ServerAdmin
webmaster@dummy-host2.example.com
DocumentRoot
"c:/wamp/www/wwwdoc/"
ServerName
www.yyy.cn
ErrorLog
"logs/www.yyy.cn-error.log"
CustomLog
"logs/www.yyy.cn-access.log" common
<Directory
"c:/wamp/www/wwwdoc/">
此段的作用是表明 www.yyy.cn做rewrite规则
Options Indexes
FollowSymLinks 因此必须打开目录浏览功能,如想禁止目录浏览
</Directory> 需要在.htaccess中指定
</VirtualHost>
最后编写.htaccess文件,在文件中加入Options All -Indexes,就可以禁止目录浏览了
(原创文章,未经作者允许,禁止转载 联系QQ 31960096)
加载中,请稍候......