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

时间:2021-05-29 11:18:44

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

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

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

有没有办法配置MAMP MAMP / conf / apachehttpd.conf,以便每个虚拟站点获得它自己的“root”?

UPDATE

After getting a clue about Virtual Hosts:

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

Have updated /etc/hosts file to include:

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

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

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

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

这是/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>

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

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

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

当浏览器指向ClientSite.localhost时,它返回404:在此服务器上找不到请求的URL /。

1 个解决方案

#1


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

以便每个虚拟站点获得它自己的“根”?

You need to use VirtualDocumentRoot.

您需要使用VirtualDocumentRoot。

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

这就是我在/Applications/MAMP/conf/apache/extra/httpd-vhosts.conf文件中在我的MAMP上使用它的方法:

<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 /%0指令。这使得每个虚拟站点的根目录为:

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:

然后只需在/ Users / admin / htdocs /中为每个如上所述的站点创建一个目录,如:

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.

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

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

还要确保在/ etc / hosts文件中有一个条目,如:

127.0.0.1    client2.localhost

for each URL in question.

对于每个有问题的网址。

#1


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

以便每个虚拟站点获得它自己的“根”?

You need to use VirtualDocumentRoot.

您需要使用VirtualDocumentRoot。

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

这就是我在/Applications/MAMP/conf/apache/extra/httpd-vhosts.conf文件中在我的MAMP上使用它的方法:

<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 /%0指令。这使得每个虚拟站点的根目录为:

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:

然后只需在/ Users / admin / htdocs /中为每个如上所述的站点创建一个目录,如:

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.

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

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

还要确保在/ etc / hosts文件中有一个条目,如:

127.0.0.1    client2.localhost

for each URL in question.

对于每个有问题的网址。