【问题标题】:localhost redirecting to path specified for sub domain本地主机重定向到为子域指定的路径
【发布时间】:2013-07-26 07:42:14
【问题描述】:

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

【问题讨论】:

  • 你用的是什么版本的蛋糕?
  • 我使用的是 cakephp 1.3

标签: apache cakephp localhost wamp


【解决方案1】:

乍一看,您的虚拟主机配置有一些奇怪的地方:

  • 第一个文档根目录没有关闭"
  • 虚拟主机名应该相同
  • 您指的是 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 上都可用

【讨论】:

  • @Jeron 必须在 httpd.conf 中添加什么来指定虚拟主机。我尝试使用 apache.org 中给出的配置,只有 client1.localhost 有效,localhost 抛出 500 错误。
  • 当我做出这个答案时,我认为这很奇怪,但这就是它在我的电脑上的工作方式。我会尝试找到执行此操作的设置。在 httpd.conf 中,我设置了“ServerName localhost:80”,其他设置仍然相同(它们都指向默认的 wamp 位置。我没有取消默认的 www 目录。)
猜你喜欢
  • 2016-10-07
  • 2014-06-21
  • 2016-04-03
  • 1970-01-01
  • 2017-10-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多