配置MAMP以将Htdocs中的每个目录视为Apache mod_redirect中的Root [英] Configure MAMP to treat each directory in Htdocs as Root in Apache mod_redirect

查看:135
本文介绍了配置MAMP以将Htdocs中的每个目录视为Apache mod_redirect中的Root的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题在于,当使用MAMP进行本地开发时,.htaccess文件需要有所不同,因为RewriteBase需要指定特定站点的子目录(如

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 MAMP/conf/apachehttpd.conf,以便每个虚拟站点都具有自己的根"目录?

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

更新

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

After getting a clue about Virtual Hosts:

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

127.0.0.1       ClientSite.localhost

取消注释:

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

/Applications/MAMP/conf/apache/httpd.conf中.

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

There is a directory called ClientSite in /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).

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

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

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

推荐答案

每个虚拟站点都有自己的根"吗?

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

您需要使用 VirtualDocumentRoot .

You need to use VirtualDocumentRoot.

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

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>

记下VirtualDocumentRoot /Users/admin/htdocs/%0指令.这使得每个虚拟站点的根为:

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

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

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

dev.localhost
client2.localhost

在此过程中删除(或重命名)任何.htaccess文件-并且一旦确认网站可通过诸如http://client2.localhost这样的url访问,则.htaccess文件应具有预期的作用.

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.

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

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

127.0.0.1    client2.localhost

每个有问题的网址.

这篇关于配置MAMP以将Htdocs中的每个目录视为Apache mod_redirect中的Root的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆