I have to run my CakePHP 2.1 application in an environment with CGI-PHP and without the ability to declare apache aliases. I want to redirect requests to a subdomain to CakePHP with mod_rewrite, but this doesn't work out.
Current setup
- Webroot is
~/user/public_html
- CakePHP is in
~/user/public_html/cakephp/
- CakePHP should be requested at
dev.mydomain.tld
What I have until now is this (all paths relative to webroot):
~/user/public_html/.htaccess
RewriteEngine on Options +FollowSymlinks RewriteCond %{HTTP_HOST} ^(www\.)?dev\.mydomain.com$ [NC] RewriteCond %{REQUEST_URI} !^/cakephp/app/webroot/ [NC] RewriteCond %{REQUEST_URI} !/$ RewriteCond %{DOCUMENT_ROOT}/cakephp/app/webroot%{REQUEST_URI}/ -d RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [R,L] RewriteCond %{HTTP_HOST} ^(www\.)?dev\.mydomain.com$ [NC] RewriteCond %{REQUEST_URI} !^/cakephp/app/webroot/ [NC] RewriteRule ^(.*)$ /cakephp/app/webroot/$1 [L]
~/user/public_html/cakephp/app/webroot/.htaccess
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php [QSA,L]
The Problem
Requests are somehow not routed correctly (the application runs without problems in my development environment with PHP as a module and an Virtual Host at the /cakephp/app/webroot/
level). When I request the home page at dev.mydomain.tld
I only get an Error, Cake is telling me, that the CakephpController is missing.
Debug information
the interesting parts of
$_SERVER
debugged as the first line in/cakephp/app/webroot/index.php
[REDIRECT_REDIRECT_REDIRECT_STATUS] => 200 [REDIRECT_REDIRECT_STATUS] => 200 [REDIRECT_HANDLER] => php-script [REDIRECT_STATUS] => On [HTTP_HOST] => dev.mydomain.tld [HTTP_CONNECTION] => keep-alive [SERVER_SOFTWARE] => Apache/2.2.21 (Unix) [SERVER_NAME] => dev.mydomain.tld [SERVER_ADDR] => 192.0.43.10 [SERVER_PORT] => 80 [DOCUMENT_ROOT] => /home/user/public_html [SCRIPT_FILENAME] => /home/user/public_html/cakephp/app/webroot/index.php [REDIRECT_URL] => /cakephp/app/webroot/index.php [GATEWAY_INTERFACE] => CGI/1.1 [SERVER_PROTOCOL] => HTTP/1.1 [REQUEST_METHOD] => GET [QUERY_STRING] => [REQUEST_URI] => / [SCRIPT_NAME] => /cakephp/app/webroot/index.php [_PHP5_WORK_DIR] => /home/user/public_html/cakephp/app/webroot [PHP_SELF] => / [ORIG_PATH_INFO] => [ORIG_PATH_TRANSLATED] => /home/user/public_html/cakephp/app/webroot/index.php [PATH_INFO] => /cakephp/app/webroot/index.php
the interesting parts of the
CakeRequest
object passed to the dispatcher:url => 'cakephp/app/webroot/index.php' base => '/cakephp' webroot => '/app/webroot/' here => '/cakephp/cakephp/app/webroot/index.php'
The question
So, what I don't get here, is why the CakeRequest object has references to my folder structure while $_SERVER['REQUEST_URI'] == '/'
. What would I have to do, to get this right? And in the first place, where should I look for the problem: in the mod_rewrite directives or in CakePHP itself?
I tried some things, including setting the RewriteBase in alle the .htaccess files and different settings for App.baseUrl
in the Configuration object, but nothing seemed to help here.
I would be really thankful if somebody could give me a pointer on how to solve this problem.
app/webroot
to the hard webroot to get around this, which will for sure only move the problem to the future. I would still be really interested in solving this, even more after seeing you had the same problem. P.S.: No WAMP involved here. – Greengrocery