一. 配置跳转
说明:
只有在启动时带上IfDefine后面配置的值作为启动脚本参数,配置才会生效
配置:
<IfDefine ToGoogle> Redirect / http://www.google.com/ </IfDefine>
运行和结果:
Apache2.2\bin>httpd.exe -DToGoogle
当访问http://ServerName:port/时,将跳转到google
二. 目录和文件
说明:
限制目录和文件访问
配置:
<Directory "D:\Program Files\Apache2.2\htdocs\test"> #Options Indexes FollowSymLinks Options FollowSymLinks AllowOverride None Order deny,allow Deny from all <Files test.htm> Order allow,deny Deny from all </Files> </Directory>
运行结果:
test 及子目录都无法访问,且目录下test.htm文件名的文件都无法访问
三. VirtualHost 基于域名的虚拟主机
配置:
NameVirtualHost * <VirtualHost *> ServerAdmin you@example.com DocumentRoot /usr/local/apache2/htdocs ServerName localhost ErrorLog /usr/local/apache2/logs/error_log TransferLog /usr/local/apache2/logs/access_log </VirtualHost> <VirtualHost *> ServerAdmin you@example.com DocumentRoot /usr/local/apache2/htdocs ServerName www.sefer.com ErrorLog /usr/local/apache2/logs/error_log TransferLog /usr/local/apache2/logs/access_log </VirtualHost> <VirtualHost *> ServerAdmin sefer@xiaofeng.com DocumentRoot /usr/local/apache2/htdocs/sefer ServerName www.test.com ErrorLog logs/test.sefer.com-error_log TransferLog logs/test.sefer.com-access_log </VirtualHost>
绑定host :
192.168.1.101 www.sefer.com www.test.com
bin/apachectl -S 可以查看httpd.conf配置结果,bin/apachectl -t 可以查看配置httpd.conf语法是否正确;
运行结果:
通过 www.sefer.com www.test.com 分别取自各自目录的默认初始文件;
四. 默认访问文件
<IfModule dir_module>
DirectoryIndex index.html </IfModule>
五. RewriteEngine
默认是不安装的,安装如下:
httpd-2.2.14/modules/mappers$ sudo /usr/local/apache2/bin/apxs -i -a -c mod_rewrite.c
<VirtualHost *>
ServerAdmin sefer@xiaofeng.com
DocumentRoot /usr/local/apache2/htdocs/sefer
ServerName www.test.com
ErrorLog logs/test.sefer.com-error_log
TransferLog logs/test.sefer.com-access_log
RewriteEngine On
RewriteRule /test/(.*) /index.html [R,L]
RewriteRule /out/(.*) http://www.163.com [R,L]
</VirtualHost>