apache的AllowOverride以及Options使用详解
通常利用Apache的rewrite模块对 URL 进行重写的时候, rewrite规则会写在 .htaccess 文件里。但要使 apache 能够正常的读取.htaccess 文件的内容,就必须对.htaccess 所在目录进行配置。
AllowOverride参数就是指明Apache服务器是否去找.htacess文件作为配置文件,如果设置为none,那么服务器将忽略.htacess文件,如果设置为All,那么所有在.htaccess文件里有的指令都将被重写。对于AllowOverride,还可以对它指定如下一些能被重写的指令类型。
不允许重写:
通常利用Apache的rewrite模块对 URL 进行重写的时候, rewrite规则会写在 .htaccess 文件里。但要使 apache 能够正常的读取.htaccess 文件的内容,就必须对.htaccess 所在目录进行配置。从安全性考虑,根目录的AllowOverride属性一般都配置成不允许任何Override ,即
<Directory />AllowOverride None</Directory>
允许重写:
在要支持url rewirte的目录启用 Options FollowSymLinks和AllowOverride All
Alias /php "E:/project_self/joomla_self/"<Directory "E:/project_self/joomla_self/">Options Indexes FollowSymLinksAllowOverride AllOrder allow,denyAllow from all</Directory>
实例:
1、windows下配置apache重定向:
apache
配置文件:Apache/Config/httpd.conf
#
# Deny access to the entirety of your server's filesystem. You must
# explicitly permit access to web content directories in other
# <Directory> blocks below.
#
<Directory />
AllowOverride AllRequire all granted
</Directory>
2、linux下配置apache重定向:
apache配置文件:Apache2/sites-available/000-default.conf
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
Alias /j /var/www/joomla
<Directory /var/www/joomla>
Options FollowSymLinks MultiViewsAllowOverride All
</Directory>