简体   繁体   English

在我的Apache的httpd.conf中使用别名指向cakephp 3.0目录会导致错误404

[英]Using an alias in my Apache's httpd.conf to point to a cakephp 3.0 directory results in error 404

On my CentOS LAMP. 在我的CentOS LAMP上。 I have a website, www.mydomain.com. 我有一个网站www.mydomain.com。 In my httpd.conf I have: 在我的httpd.conf中,我有:

<VirtualHost *:80>
    ServerAdmin me@myemail.com
    DocumentRoot /var/www/cakephp
    ServerName www.mydomain.com
    <Directory /var/www/cakephp/>
        Options FollowSymLinks
        AllowOverride All
    </Directory>
</VirtualHost>

So www.mydomain.com is served from /var/www/cakephp. 因此,www.mydomain.com是从/ var / www / cakephp提供的。

But I want it so that URL "www.mydomain.com/powercontroller/" is served from: /var/www/powercontroller. 但是,我希望从“ / var / www / powercontroller”提供URL“ www.mydomain.com/powercontroller/”。 So I put this alias into httpd.conf as well: 所以我也把这个别名放到httpd.conf中:

Alias /powercontroller/ "/var/www/powercontroller/"
<Directory "/var/www/powercontroller/">
    AllowOverride All
</Directory>

But it doesn't work. 但这是行不通的。 The URL "www.mydomian.com/powercontroller" in my browser gives me error 404 "The requested URL /var/www/powercontroller/webroot/ was not found on this server." 我的浏览器中的URL“ www.mydomian.com/powercontroller”给我错误404“在此服务器上找不到请求的URL / var / www / powercontroller / webroot /”。

My /var/www/powercontroller directory has the following: 我的/ var / www / powercontroller目录具有以下内容:

.htaccess .htaccess

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

index.php index.php

require 'webroot' . DIRECTORY_SEPARATOR . 'index.php';

These are the default files from Cakephp 3.0 setup. 这些是Cakephp 3.0安装程序中的默认文件。 And there is certainly a webroot directory with everything in place from the default Cakephp 3.0. 当然还有一个webroot目录,所有目录都来自默认的Cakephp 3.0。

I know I must be partway there because at least it's looking in the powercontroller directory. 我知道我必须在那儿,因为至少它在powercontroller目录中。 But for some reason it insists it cannot find the webroot. 但是由于某种原因,它坚持认为找不到根目录。

OK I figured it out. 好,我知道了。 When you alias to a cakephp 3.0 app directory then your .htaccess in both your app directory and your webroot directory needs a RewriteBase directive. 当您别名为cakephp 3.0应用程序目录时,则您的应用程序目录和webroot目录中的.htaccess都需要RewriteBase指令。 So in my case file /var/www/powercontroller/.htaccess and file /var/www/powercontroller/webroot/.htaccess both need the line: 因此,在我的情况下,文件/var/www/powercontroller/.htaccess和文件/var/www/powercontroller/webroot/.htaccess都需要以下行:

RewriteBase /powercontroller/

right below their line 就在他们的线下

RewriteEngine on 

This information is found almost nowhere. 这些信息几乎找不到。 Here's a similar question that was never answered correctly, that I'll now answer. 这是一个类似的问题,但从未得到正确回答,我现在将回答。 And here's an analogous answer about drupal that was the only clue I found in a week of searching. 这是关于drupal的类似答案,这是我在一周的搜索中发现的唯一线索。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM