0

在 cakephp 中,我想将 localhost 重定向到 app2,将 client1.localhost 重定向到 app1。相反,两者都重定向到 app1。

我的 httpd-vhost 定义为:

    NameVirtualHost 127.0.0.1
<VirtualHost 127.0.0.1> 
    DocumentRoot "D:\wamp\www\cakephp\app2\webroot\
    ServerName localhost
</VirtualHost>

<VirtualHost www.myhost> 
    DocumentRoot "D:\wamp\app1\webroot"
    ServerName client1.localhost
    ServerAlias client1.localhost
    <Directory "D:\wamp\app1\webroot">
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Order allow,deny
        Allow from all
   </Directory>
</VirtualHost>
4

1 回答 1

1

乍一看,您的 vhost 配置有一些奇怪的地方:

  • 第一个文档根目录没有关闭"
  • 虚拟主机名称应该相同
  • 您指的是 webroot,而不是 approot(您的 approot 中还有一个 .htacces)

我将 CakePHP 2.x 与 wamp 服务器一起使用,配置如下:

确保在您的 apache 配置中取消注释 vhost 文件:wamp/bin/apache/Apache[version]/conf/httpd.conf(或左键单击 wamp->apache->httpd.conf)

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

在 wamp/bin/apache/Apache[version]/conf/extra/httpd-vhosts.conf 试试这个

#
# Use name-based virtual hosting.
#    
NameVirtualHost *:80

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
    ServerName client1.localhost
    DocumentRoot "D:\wamp\app1"
    <Directory "D:\wamp\app1">
        Options FollowSymLinks
        AllowOverride All
        Allow from all
    </Directory>

    DirectoryIndex index.html index.php
</VirtualHost>

<VirtualHost *:80>
    ServerName dev.localhost
    DocumentRoot "D:\wamp\www\cakephp\app2"

    <Directory "D:\wamp\www\cakephp\app2">
        Options FollowSymLinks
        AllowOverride All
        Allow from all
    </Directory>

    DirectoryIndex index.html index.php
</VirtualHost>

并将其放入您的主机文件(C:\windows\system32\drivers\etc)

127.0.0.1       localhost
127.0.0.1       dev.localhost
127.0.0.1       client1.localhost

重新启动所有服务。App2 将在 localhost 和 dev.localhost 上可用

于 2013-07-26T08:32:21.970 回答