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#blocks below.# #Options Indexes MultiViews Require all granted AllowOverride none # Require all denied
2. vim/etc/apache2/extra/httpd-vhosts.conf
增加 VirtualHost,并且将 Directory的配置写好,如下的配置
DocumentRoot "/Users/caoxin/wwwroot/xxx/movie_platform/public" ServerName api.movie.com Options FollowSymLinks AllowOverride All Require all granted ErrorLog "/private/var/log/apache2/api_movie-error_log" CustomLog "/private/var/log/apache2/api_movie-access_log" common
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测试实例:
# BEGINRewriteEngine onRewriteBase /RewriteRule .*$ http://www.baidu.com #END
测试方法: 访问网站任何路径页面,均会跳转到本博客,说明Rewrite已生效。
提醒:正常修改.htaccess一般都是即时生效,如果修改的是apache conf配置文件,一般需要重启apache一次。