带有Apache Alias子目录的CakePHP App指向不同的CakePHP代码目录,导致无限重定向到index.php

时间:2016-01-20 14:30:17

标签: php apache .htaccess cakephp mod-rewrite

我有两个网站,都是CakePHP。它们在 domaina.com domainb.com 上提供,文档根分别为/home/weba/root/home/webb/root。我需要从与DocumentRoot不同的目录中提供网址 domaina.com/directory /home/webb/root而不是/home/weba/root,如下面的VHost中所配置的那样。

我已经尝试过Alias和AliasMatch,而我所获得的最远的是获取网址以引发“太多重定向”"将index.php添加到域中的错误,直到它看起来像: domaina.com/directory/index.php/index.php/index.php/index.php ...

我认为造成无限重定向的原因是/home/webb/root/app/webroot/

中的.htaccess文件

这就是我所得到的:

<VirtualHost *:443>

DocumentRoot "/home/weba/root"

ServerName www.domaina.com
SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW
SSLCertificateFile ...
SSLCertificateKeyFile ...
SSLCertificateChainFile ...
<Files ~ "\.(cgi|shtml|phtml|php3?)$">
    SSLOptions +StdEnvVars
</Files>
<Directory "/var/www/cgi-bin">
    SSLOptions +StdEnvVars
</Directory>

    AliasMatch "^/directory(.*)" "/home/webb/root"
    <Directory "/home/webb/root">
        Options All -Indexes
        AllowOverride All
        order allow,deny
        allow from all
    </Directory>

SetEnvIf User-Agent ".*MSIE.*" \
         nokeepalive ssl-unclean-shutdown \
         downgrade-1.0 force-response-1.0


CustomLog logs/ssl_request_log \
          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

</VirtualHost>

请注意,每个代码库都有一个标准的CakePHP .htaccess文件,将所有内容指向/ app / webroot:

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]
</IfModule>

app / webroot中的另一个.htaccess:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
</IfModule>

编辑: 我甚至尝试添加一个符号链接:/home/weba/root/app/webroot/directory链接到/home/webb/root/app/webroot哪种工作方式,但任何不符合标志性链接的目录(比如domaina.com/directory/page)最终都会获得从domaina的根目录提供服务,因为它不再符合预期的RewriteCond %{REQUEST_FILENAME} !-d规则 - 这让我觉得符号链接路由不可行。

1 个答案:

答案 0 :(得分:0)

首先,我没有得到您想要满足的确切要求。

我将首先尝试不删除RewriteBase,并将其命名为您正在使用的子模板。

最后,我认为你应该尝试控制mod_rewrite是否正常工作,以及apache域文件中的某些指令是否干扰你的htaccess规则。

但是,如果您根据所需的基本要求简化问题,我认为您会得到更多反馈。

如果没有更多信息,我只能指向一位htaccess测试人员:

http://www.htaccesscheck.com/

验证您的语法以及适用的规则。

编辑:

在阅读完更改后,我想我知道你要做什么,从其网络根目录服务主应用程序,但在某个目录下的网址由其他应用程序或网络根目录处理。我已经完成了这样的事情(但是在Apache .conf文件下编写,而不是在.htaccess中编写)

I've made something similar to host a blog with wordpress, but I put all this directives under the conf file:


<Directory /path/to/my/web/app>
Options -Indexes +IncludesNOEXEC +SymLinksIfOwnerMatch
allow from all
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
</Directory>

Alias /blog /path/to/my/web/blog
<Directory /path/to/my/web/blog>
Options -Indexes +IncludesNOEXEC +SymLinksIfOwnerMatch
allow from all
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
</Directory>

选项部分是可选的,我已准备好使用我的配置。

有了这个,我可以在其他目录中安装wordpress的/ blog网址。不知道这是不是你想要的。