.htaccess 档案是目录层面的设定档, 可以对目录变更 Apache 的设定, 例如更改 DocumentIndex, 转址及密码保护等在 httpd.conf 的设定。
要使用 .htaccess 档案, 需要在 Apache 的设定档 (httpd.conf 或 apache2.conf) 开启使用, 否则 Apache 是不会处理 .htaccess 的设定的。
开启 .htaccess, 首先开档 Apache 的设定档
Redhat, CentOS 及 Fedora 开启 /etc/httpd/conf/httpd.conf:
$ sudo vi /etc/httpd/conf/httpd.conf
Debian 及 Ubuntu 开启 /etc/apache2/apache2.conf:
$ sudo vi /etc/apache2/apache2.conf
找到以下字串:
在以上一行的段落下面, 会有一行 “AllowOverride None”, 改为:
AllowOverride All
储存盘案后离开编辑器, 重新启动 Apache 便会生效。
CentOS 7:
$ sudo systemctl restart httpd
CentOS 6:
$ sudo service restart httpd
Debian / Ubuntu:
$ sudo service apache2 restart