Reputation: 126
Having trouble configuring CakePhp on an Apache server. It worked fine in my dev environment, and now I'm looking to deploy.
The url will look like:
"http://www.example.com/mysite/"
A sample controller action would be:
"http://www.example.com/mysite/users/login"
Using the default htaccess files doesn't seem to work.
mod_rewrite is loaded according to phpInfo, and it is rewriting urls, but it sees /mysite/ as a controller. Here is the output and my .htaccess files
Missing Controller
Error: MysiteController could not be found.
Error: Create the class MysiteController below in file: >app/Controller/MysiteController.php
root:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
app:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
webroot:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
</IfModule>
Should I be looking to change my .htaccess files, or my CakePhp config file? I've tried a few different RewriteBases, only managed to get different errors.
Edit: The server is running php-cgi and it appears all of my links are being written to a cgi-bin. For example:
$this->Html->meta('icon');
writes the path "/cgi-bin/cgiwrap/w3u_mysite/mysite/favicon.ico" Any idea as to where or why this could be happening?
Upvotes: 2
Views: 5390
Reputation: 126
As suspected in my edit, the problem was related to the server running cgi php. I'm not exactly sure what the issue was, but the CakePhp google group provided this solution:
In app/Config/core.php there is a commented out definition for App.baseUrl. Uncomment it and replace with the following
Configure::write('App.baseUrl', '/mysite/');
Above it, there are comments saying to remove the .htaccess files that you should ignore. The site worked fine with the .htaccess files as their standard values, no RewriteBase needed. The one annoyance was that $this->Html->css()
and $this->Html->js()
functions did not work, but I only call them in templates, so it's not terrible to hard code them.
If anyone has insight into the cause of these cgi woes, please share. It still feels a bit like a kludge if I can't use all of the Html helpers.
Upvotes: 3
Reputation: 1677
I have similar issues with some servers. Solution for me was to name the absolute path in all .htaccess files.
Something like:
root:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^$ /mysite/app/webroot/ [L]
RewriteRule (.*) /mysite/app/webroot/$1 [L]
</IfModule>
app:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^$ /mysite/app/webroot/ [L]
RewriteRule (.*) /mysite/app/webroot/$1 [L]
</IfModule>
webroot:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /mysite/app/webroot/index.php?/$1 [QSA,L]
</IfModule>
Upvotes: 0
Reputation: 651
You'll want to add Rewritebase /mysite/
(possibly with '/mysite' quoted or without the second slash , you'll have to try) to your .htaccesses, so mod rewrite will take the folder in account.
Have you checked you webroot/index.php
file for correct paths?
As a last resort maybe filter out 'mysite' in the routes?
Final suggestion: prepend mysite/
to app
in your rewriterules.
Upvotes: 0