在我的Apache的httpd

在我的Apache的httpd

本文介绍了在我的Apache的httpd.conf中使用别名指向cakephp 3.0目录会导致错误404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的CentOS灯泡上.我有一个网站www.mydomain.com.在我的httpd.conf中,我有:

On my CentOS LAMP. I have a website, www.mydomain.com. In my httpd.conf I have:

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot /var/www/cakephp
    ServerName www.mydomain.com
    <Directory /var/www/cakephp/>
        Options FollowSymLinks
        AllowOverride All
    </Directory>
</VirtualHost>

因此,从/var/www/cakephp提供www.mydomain.com.

So www.mydomain.com is served from /var/www/cakephp.

但是我想要这样,以便从以下位置提供URL"www.mydomain.com/powercontroller/":/var/www/powercontroller.所以我也把这个别名放到httpd.conf中:

But I want it so that URL "www.mydomain.com/powercontroller/" is served from: /var/www/powercontroller. So I put this alias into httpd.conf as well:

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

但是它不起作用.我的浏览器中的URL"www.mydomian.com/powercontroller"给我错误404在此服务器上找不到所请求的URL/var/www/powercontroller/webroot/."

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."

我的/var/www/powercontroller目录具有以下内容:

My /var/www/powercontroller directory has the following:

.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';

这些是Cakephp 3.0安装程序中的默认文件.当然还有一个webroot目录,所有目录都来自默认的Cakephp 3.0.

These are the default files from Cakephp 3.0 setup. And there is certainly a webroot directory with everything in place from the default Cakephp 3.0.

我知道我必须在那儿,因为至少它在powercontroller目录中.但是出于某种原因,它坚持认为找不到根目录.

I know I must be partway there because at least it's looking in the powercontroller directory. But for some reason it insists it cannot find the webroot.

推荐答案

好,我知道了.当您别名为cakephp 3.0应用程序目录时,则您的应用程序目录和webroot目录中的.htaccess都需要RewriteBase指令.因此,在我的情况下,文件/var/www/powercontroller/.htaccess和文件/var/www/powercontroller/webroot/.htaccess都需要以下行:

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. So in my case file /var/www/powercontroller/.htaccess and file /var/www/powercontroller/webroot/.htaccess both need the line:

RewriteBase /powercontroller/

在其行的正下方

RewriteEngine on

几乎找不到该信息. 这是一个类似的问题,但从未得到正确回答,我现在将回答.并且这是关于drupal的类似答案,这是我在一周的搜索中唯一发现的线索.

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.

这篇关于在我的Apache的httpd.conf中使用别名指向cakephp 3.0目录会导致错误404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-27 11:04