How to change the location of webroot in CakePHP?
Is there a way to keep the webroot folder at the actual root?
To explain: what should I do to achieve a folder structure like this:
app/
cake/
css/
files/
img/
js/
plugins/
vendors/
开发者_JAVA技巧With everything working as it should.
You are doing mistake of exposing your code to public.
/project/
/project/app/
...
/project/css/
/project/js/
...
However if you still want to set /project/
as your webroot, place this into .htaccess
file
// /project/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app/webroot/index.php?url=$1 [QSA,L]
</IfModule>
Recommendation: You should stick to the default directory structure of CakePHP, because it's proven secure and best practice to do most kind of applications.
I understand you want your workflow to be simplified, with top-level access to the directories you use frequently. However, it isn't wise to have your main sourcecode inside the web root.
You can instead use symlinks to link to the static folders (css
, img
, js
, etc).
精彩评论