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/.htaccessRewriteEngine 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/.htaccessRewriteEngine 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
$_SERVERdebugged 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
CakeRequestobject 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.
Then I’ll give you a pointer as I don’t know the answer. 🙂
Have you read this question where I had a problem quite similar to yours?