- 在 /private/etc/apache2/ 目录下找到 httpd.conf 并打开
找到:
# Virtual hosts
#Include /private/etc/apache2/extra/httpd-vhosts.conf
去掉 Include 前的 # 号
# Virtual hosts
Include /private/etc/apache2/extra/httpd-vhosts.conf
可以把 /private/etc/apache2/extra/ 下的 httpd-vhosts.conf
复制到自己的目录下以方便修改,并修改配置
# Virtual hosts
Include /Users/yourname/Sites/httpd-vhosts.conf
- 在 httpd-vhosts.conf 中添加站点配置
<VirtualHost *:80>
ServerAdmin webmaster@test.com
DocumentRoot "/Users/yourname/Sites/www.test.com"
ServerName www.test.com
<Directory "/Users/yourname/Sites/www.test.com">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog "/Users/yourname/Sites/www.test.com/tests.com-error_log"
CustomLog "/Users/yourname/Sites/www.test.com/test.com-access_log" common
</VirtualHost>
- 重启 apachectl 服务
sudo apachectl restart
即可
如需配置 url rewrite(地址重写)
- 打开 /private/etc/apache2/httpd.conf 找到
#LoadModule rewrite_module libexec/apache2/mod_rewrite.so
去掉前面的 # 号
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
- 在虚拟主机配置文件 httpd-vhosts.conf 中
<Directory "/Users/yourname/Sites/www.test.com">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
AllowOverride None 要改为 AllowOverride All
- 在站点目录下添加 .htaccess 文件
<IfModule mod_rewrite.c>
RewriteEngine on
#RewriteCond
RewriteRule address1.php address2.php
</IfModule>
根据地址重写规则编写 RewriteCond RewriteRule
网友评论