配置MAMP将Htdocs中的每个目录视为Apache mod_redirect中的Root

时间:2015-05-11 19:29:13

标签: apache .htaccess mod-rewrite mamp

问题是当使用MAMP进行本地开发时,.htaccess文件需要区别在于RewriteBase需要指定特定站点的子目录(如图here on SO所示)

有没有办法配置MAMP MAMP/conf/apachehttpd.conf,以便每个虚拟网站都拥有它" root"?

更新

获得有关虚拟主机的线索后:

已更新/etc/hosts文件以包含:

127.0.0.1       ClientSite.localhost

取消评论该行:

`#Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf` 
/Applications/MAMP/conf/apache/httpd.conf中的

ClientSite中有一个名为/Users/myname/Sites/的目录。

这是/Applications/MAMP/conf/apache/extra/httpd-vhosts.conf内容:

NameVirtualHost *:80
<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    ServerName localhost
    ServerAlias *.localhost
    VirtualDocumentRoot /Users/myname/Sites/%0

    RewriteLogLevel 3
    RewriteLog "/Applications/MAMP/logs/rewrite.log"

    <Directory /Users/myname/Sites>
       Options All
       AllowOverride All
       Order allow,deny
       Allow from all
    </Directory>
</VirtualHost>

重新启动MAMP服务器(甚至运行dscacheutil -flushcache)。

当浏览器指向ClientSite.localhost时,它会返回404The requested URL / was not found on this server.

1 个答案:

答案 0 :(得分:1)

  

以便每个虚拟网站都拥有自己的&#34; root&#34;?

您需要使用VirtualDocumentRoot

这就是我在MAMP文件/Applications/MAMP/conf/apache/extra/httpd-vhosts.conf中使用此功能的方式:

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    ServerName localhost
    ServerAlias *.localhost
    VirtualDocumentRoot /Users/admin/htdocs/%0

    RewriteLogLevel 3
    RewriteLog "/Applications/MAMP/logs/rewrite.log"

    <Directory /Users/admin/htdocs>
       Options All
       AllowOverride All
       Order allow,deny
       Allow from all
    </Directory>
</VirtualHost>

注意VirtualDocumentRoot /Users/admin/htdocs/%0指令。这使得每个虚拟站点的根目录为:

VirtualDocumentRoot /Users/admin/htdocs/localhost
VirtualDocumentRoot /Users/admin/htdocs/dev.localhost
VirtualDocumentRoot /Users/admin/htdocs/client2.localhost

然后只需在/Users/admin/htdocs/内为上面命名的每个网站创建一个目录,例如:

dev.localhost
client2.localhost

在此过程中删除(或重命名)任何.htaccess个文件 - 并且一旦确认网站可通过以下网址访问:http://client2.localhost.htaccess文件应按预期运行。

另外请确保在/etc/hosts文件中有以下条目:

127.0.0.1    client2.localhost

对于每个相关网址。