MAC OSX 10.10 下启用自带的Apache的rewrite模块
1.修改Apache配置文件
sudo vim /etc/apache2/httpd.conf
LoadModule rewrite_module libexec/apache2/mod_rewrite.so 去掉该行前面的#
注释掉 #Require all denied,
增加一行 Require all granted
# 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 /> #Options Indexes MultiViews Require all granted AllowOverride none # Require all denied </Directory>
2. vim/etc/apache2/extra/httpd-vhosts.conf
增加 VirtualHost,并且将 Directory的配置写好,如下的配置
<VirtualHost *:80> DocumentRoot "/Users/caoxin/wwwroot/xxx/movie_platform/public" ServerName api.movie.com <Directory "/Users/caoxin/wwwroot/xxx/movie_platform/public"> Options FollowSymLinks AllowOverride All Require all granted </Directory> ErrorLog "/private/var/log/apache2/api_movie-error_log" CustomLog "/private/var/log/apache2/api_movie-access_log" common </VirtualHost>
3. 修改本机的host设置 (vim /etc/hosts)
127.0.0.1 xxx.com
4. 重启apache
sudo apachectl restart
ps -ef |grep httpd
5.测试rewrite的功能
在网站的根路径下,创建.htaccess文件,将该文件的权限设置为777
sudo chmod 777 .htaccess
以下为.htaccess测试实例:
# BEGIN <IfModule mod_rewrite.c> RewriteEngine on RewriteBase / RewriteRule .*$ http://www.baidu.com </IfModule> #END
测试方法: 访问网站任何路径页面,均会跳转到本博客,说明Rewrite已生效。
提醒:正常修改.htaccess一般都是即时生效,如果修改的是apache conf配置文件,一般需要重启apache一次。