localhost重定向到为子域指定的路径

时间:2013-07-26 07:42:15

标签: apache cakephp localhost wamp

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

1 个答案:

答案 0 :(得分:1)

乍一看,你的vhost配置有一些奇怪的东西:

  • 第一个文档根目录没有关闭“
  • 虚拟主机名称应该都是相同的
  • 您指的是webroot,而不是Approot(在您的许可中也有.htacces)

我使用带有wamp服务器的CakePHP 2.x,配置如下:

确保在您的apache配置中取消注释vhost文件: wamp / bin / apache / Apache [version] /conf/httpd.conf(或左键单击wamp-&gt; apache-&gt; 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

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

上可用