Configure MAMP to treat each directory in Htdocs as Root in Apache mod_redirect

▼魔方 西西 提交于 2019-12-08 13:32:34
anubhava

so that each virtual site gets it's own "root"?

You need to use VirtualDocumentRoot.

This is how I am using this on my MAMP in my /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf file:

<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>

Take note of VirtualDocumentRoot /Users/admin/htdocs/%0 directive. That makes each virtual site's root as:

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

etc.

Then simply create a directory within /Users/admin/htdocs/ for each site named as above, like:

dev.localhost
client2.localhost

Remove (or rename) any .htaccess files during the process - and once websites confirmed to be accessible via url like: http://client2.localhost, .htaccess files should behave as expected.

Also be sure that in the /etc/hosts file, there's an entry like:

127.0.0.1    client2.localhost

for each URL in question.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!