Note that there are some explanatory texts on larger screens.

plurals
  1. POCakePHP, CGI and mod_rewrite
    text
    copied!<p>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.</p> <p><strong>Current setup</strong></p> <ul> <li>Webroot is <code>~/user/public_html</code></li> <li>CakePHP is in <code>~/user/public_html/cakephp/</code></li> <li>CakePHP should be requested at <code>dev.mydomain.tld</code></li> </ul> <p>What I have until now is this (all paths relative to webroot):</p> <ul> <li><p><code>~/user/public_html/.htaccess</code></p> <pre><code>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] </code></pre></li> <li><p><code>~/user/public_html/cakephp/app/webroot/.htaccess</code></p> <pre><code>RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php [QSA,L] </code></pre></li> </ul> <p><strong>The Problem</strong></p> <p>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 <code>/cakephp/app/webroot/</code> level). When I request the home page at <code>dev.mydomain.tld</code> I only get an Error, Cake is telling me, that the CakephpController is missing.</p> <p><strong>Debug information</strong></p> <ul> <li><p>the interesting parts of <code>$_SERVER</code> debugged as the first line in <code>/cakephp/app/webroot/index.php</code></p> <pre><code> [REDIRECT_REDIRECT_REDIRECT_STATUS] =&gt; 200 [REDIRECT_REDIRECT_STATUS] =&gt; 200 [REDIRECT_HANDLER] =&gt; php-script [REDIRECT_STATUS] =&gt; On [HTTP_HOST] =&gt; dev.mydomain.tld [HTTP_CONNECTION] =&gt; keep-alive [SERVER_SOFTWARE] =&gt; Apache/2.2.21 (Unix) [SERVER_NAME] =&gt; dev.mydomain.tld [SERVER_ADDR] =&gt; 192.0.43.10 [SERVER_PORT] =&gt; 80 [DOCUMENT_ROOT] =&gt; /home/user/public_html [SCRIPT_FILENAME] =&gt; /home/user/public_html/cakephp/app/webroot/index.php [REDIRECT_URL] =&gt; /cakephp/app/webroot/index.php [GATEWAY_INTERFACE] =&gt; CGI/1.1 [SERVER_PROTOCOL] =&gt; HTTP/1.1 [REQUEST_METHOD] =&gt; GET [QUERY_STRING] =&gt; [REQUEST_URI] =&gt; / [SCRIPT_NAME] =&gt; /cakephp/app/webroot/index.php [_PHP5_WORK_DIR] =&gt; /home/user/public_html/cakephp/app/webroot [PHP_SELF] =&gt; / [ORIG_PATH_INFO] =&gt; [ORIG_PATH_TRANSLATED] =&gt; /home/user/public_html/cakephp/app/webroot/index.php [PATH_INFO] =&gt; /cakephp/app/webroot/index.php </code></pre></li> <li><p>the interesting parts of the <code>CakeRequest</code> object passed to the dispatcher:</p> <pre><code> url =&gt; 'cakephp/app/webroot/index.php' base =&gt; '/cakephp' webroot =&gt; '/app/webroot/' here =&gt; '/cakephp/cakephp/app/webroot/index.php' </code></pre></li> </ul> <p><strong>The question</strong></p> <p>So, what I don't get here, is why the CakeRequest object has references to my folder structure while <code>$_SERVER['REQUEST_URI'] == '/'</code>. 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 <code>App.baseUrl</code> in the Configuration object, but nothing seemed to help here.</p> <p>I would be really thankful if somebody could give me a pointer on how to solve this problem.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload