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

纵然是瞬间 提交于 2019-12-08 06:48:10

问题


The issue is that when using MAMP for local development, the .htaccess file needs to differ in that the RewriteBase needs to specify the subdirectory for the specific site (as shown here on SO).

Is there a way to configure MAMP MAMP/conf/apachehttpd.conf so that each virtual site gets it's own "root"?

UPDATE

After getting a clue about Virtual Hosts:

Have updated /etc/hosts file to include:

127.0.0.1       ClientSite.localhost

Uncommented the line:

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

in /Applications/MAMP/conf/apache/httpd.conf.

There is a directory called ClientSite in /Users/myname/Sites/.

This is the /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf content:

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>

Restarted the MAMP servers (and even ran dscacheutil -flushcache).

When browser is pointed to ClientSite.localhost it returns a 404: The requested URL / was not found on this server.


回答1:


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.



来源:https://stackoverflow.com/questions/30176078/configure-mamp-to-treat-each-directory-in-htdocs-as-root-in-apache-mod-redirect

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