从外部文档根加载CakePHP应用程序

时间:2014-04-01 13:16:39

标签: apache cakephp mod-rewrite alias

我试图从另一个文档根目录加载CakePHP应用程序。

这是我的Apache配置:

<VirtualHost *:443>
    ServerName internet.com
    DocumentRoot "/sites/internet"

    ...

    Alias /developer "/sites/intranet/developer"

</VirtualHost>

但是,当我访问internet.com/developer/cakeapp/portal时,我会收到404.如果我访问intranet.com/developer/cakeapp/portal,则可以使用。

Intranet站点的工作配置:

<VirtualHost *:443>
        ServerName intranet.com
        DocumentRoot "/sites/intranet"

            ...

        <Directory "/sites/intranet/developer/cakeapp">
            <IfModule mod_rewrite.c>
              RewriteEngine On
              RewriteBase /developer/cakeapp
              RewriteCond %{REQUEST_FILENAME} !-d
              RewriteCond %{REQUEST_FILENAME} !-f
              RewriteCond %{REQUEST_METHOD} !OPTIONS
              RewriteRule ^(.*)$ app/webroot/index.php?url=$2 [QSA,L]
            </IfModule>
        </Directory>
</VirtualHost>

我是否应该在互联网VirtualHost配置中包含mod_rewrites?我曾假设他们会在访问Intranet网站时进行翻译。

注意:此设置位于配置为模仿Intranet和Internet托管的开发服务器上。目标是在两个域上重用门户网站。

更新#1

使用Cake 2.4.5

更新#2

查看我的SSL错误日志文件,我注意到了这一点: File does not exist: /sites/intranet/developer/cakeapp/users

该应用重定向到users/login,所以看起来其中一些正在发挥作用。仍然没有解释404。

更新#3

正在使用新的重写规则:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /developer/cakeapp
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !^/(app/webroot/)?(img|css|js)/(.*)$
    RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>

1 个答案:

答案 0 :(得分:0)

这是有效的配置。我不得不从Intranet配置中复制一些配置元素,我认为这些配置元素在别名过程中会被应用。

<VirtualHost *:443>
    ServerName internet.com
    DocumentRoot "/sites/internet"

    ...

    Alias /developer "/sites/intranet/developer"

    <Directory "/sites/intranet/developer">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all

        RewriteEngine on
        RewriteBase /developer/cakeapp
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_URI} !^/(app/webroot/)?(img|css|js)/(.*)$
        RewriteRule ^(.*)$ index.php [QSA,L]

    </Directory>

</VirtualHost>