Hi every body!
I’d like to share my real experience from the last project that I need to deploy my cakephp project as a sub folder.
Recently, I have a request to deploy our project as sub-folder. It heard simple. But in reality, I met some trouble, so I’d like to share with you.
Basicly, we will resolve it by .htaccess:
- my DocumentRoot is /var/www/html/projectA/app/webroot is running for septeni-technology.jp
- I’d like to setup for my cakephp project( projectB) at sub directory at : projectA/projectB, so it can be accessed as septeni-technology.jp/projectB/
- my deployment environment is LAMP, on window there’s small difference for variables but concept should be the same.
1. edit/create the .htaccess at your /var/www/html/projectA/
RewriteRule ^projectB/(.*)$ projectB/app/webroot/1$ [L,QSA]
2. add RewriteBase to projectB/.htaccess & projectB/app/.htaccess
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
owww.. if your source code is perfect, maybe that’s enough, it’s working well! congrats!
But in my case, it’s a bit complicated that the source code is developed by many developers for years! Oh my goD!
so there’re many absolute links in source code, in my case, there’re hundreds.
- redirect(‘/’), redirect(‘/profiles’) …
- <img src = “/img/icon/icon_search.png”..
- location.href = ‘/’ +..
- < href = “/…”
- ajaxSend(data, callback, url);
So my solution is search & replace all! It hear mad, but I can’t check all codes line by line. Here’re my steps:
- at config file, I set a global definition:
- at PHP side, it should have no links at Models, Components. Almost wrong link is at Controllers with redirect(), so let search then replace:
1$this->redirect('/ =replace=>; $this->redirect( WWW_ALIAS .'/
- at View, there’re some cases can make wrong links:
- form submit
- search for keyword ‘form’ and check for ‘action’ link.
- src = ‘/ ==> src =<?php echo WWW_ALIAS;?>
- a href
1href = '/ ==> href ='<!--?php echo WWW_ALIAS;?-->/
- form submit
- at webroot/css
- image link can be wrong: search for “url(/” => change to relative link.
1var WWW_ALIAS ='';
- in js files, search for images “/img”, “location.href”, ajax request ajax( ..
1'/img..' ==> '/' + WWW_ALIAS + ''img..'
1href ='/ (in js we generated html too)
This is reported by VietNC @ septeni-technolofy.