简体   繁体   中英

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. I have a website, www.mydomain.com. In my httpd.conf I have:

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

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>

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

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

.htaccess

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

index.php

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

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.

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.

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/

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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