Run cakephp app in apache alias

2019-07-09 03:01发布

问题:

I'm trying to deploy a cakephp 3.1 app in a apache 2.4 powered server. My boss would like to place the app in a directory different of server's documentroot (DocumentRoot "/var/www/html" in my httpd.conf file), since multiple webapps will be served by this server.

Instead of virtualhosts, he would like to use aliases (host/app1, host/app2 etc). So I'm trying to configure it this way. I put an alias to my cake app (Alias "/scqa" "/opt/scqa/webroot" in my httpd.conf file) and wrote a RewriteBase (RewriteBase /scqa) to both cake's .htaccess files, but every absolute link present in my app is still pointing to apache's documentroot. In this particular case, it means my css and a big pile of not properly built links are 404ing. Is there some way I can fix it in apache configuration? I know 2 other ways to fix it: Fix the links with cake syntax (will take me a week) or use virtualhosts. But is it possible to fix it and keep using apache alias?

Thanks in advance.

(The production env uses centos 7 64bits, just in case)

回答1:

If I understood well, you are using aliases in your .htaccess files. You should put the Alias in your server config file, because it won't work otherwise.

Syntax: Alias [URL-path] file-path|directory-path

Context: server config, virtual host, directory

From https://httpd.apache.org/docs/current/mod/mod_alias.html