CakePHP installation in /~username/

In a recent project for of our client the domain had not yet transfered to the new server and we had to install and demo a CakePHP app from a URL which was something like http://ourdomain.tld/~username/

While everything worked properly on the local machine the above URL was giving 404 Not found Errors. We solved it pretty easily but today on the CakePHP group I came across a post where the user had a very similar problem... So I thought that I might as well write the solution so that it can help more people

The solution involves editing the .htaccess file and adding the /~username/ to the path. The default outer most .htaccess looks like

CODE:
  1. <IfModule mod_rewrite.c>
  2.    RewriteEngine on
  3.    RewriteRule    ^$ app/webroot/    [L]
  4.    RewriteRule    (.*) app/webroot/$1 [L]
  5. </IfModule>

Just change it to

CODE:
  1. <IfModule mod_rewrite.c>
  2.    RewriteEngine on
  3.    RewriteRule    ^$ /~username/app/webroot/    [L]
  4.    RewriteRule    (.*) /~username/app/webroot/$1 [L]
  5. </IfModule>

The above worked for us, may be you will also need to make corresponding changes in the .htaccess which is in the /app

Thanks to Abbas Ali for this solution

Update: The solution is already there in the manual which consists of using RewriteBase /~username/ - but I am sure it was not there the last time I read it!

About Tarique Sani

Dr. Tarique Sani is a pediatrician and forensic expert by education. He is a PHP programmer of 'wrote the book' caliber and has to his credit several very popular open source as well as commercial PHP projects. He leads a team of dynamic programmers at SANIsoft who have in-depth understanding of Web development tools and usability practices with strong developmental skills in PHP, MySQL/PostgreSQL, HTML, DHTML, Javascript, and Linux/Apache
No comments yet.

Leave a Reply