0
votes

Just curious how does CakePHP rewrite Urls

.htaccess for cakephp at root is

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]
</IfModule>

which generates normal css links for CakePHP as <link rel="stylesheet" type="text/css" href="/cake/css/cake.generic.css" />

/cake/css/cake.generic.css The path to this file is C:\xampp\htdocs\cake\app\webroot\css\cake.generic.css which is achieved by the above .htaccess code.

but, if we add the DebugKit (for example) or any other plugin to cakephp the css files are rewritten as <link rel="stylesheet" type="text/css" href="/cake/debug_kit/css/debug_toolbar.css" />

/cake/debug_kit/css/debug_toolbar.css The path to this file is C:\xampp\htdocs\cake\app\Plugin\DebugKit\webroot\css\debug_toolbar.css

I am searching for a .htaccess file which does this, but could not find one. What is the way that CakePHP has achieved this or one can achieve this.

1
This is most likely not achieved by using htaccess, but rather a router script that detects which plugin the CSS file belongs to.Daniel

1 Answers

1
votes

This is not just htaccess, this uses the AssetDispatcher: http://book.cakephp.org/2.0/en/development/dispatch-filters.html

This way it essentially routes the assets via CakePHP Dispatcher, which uses PHP and is a little bit more overhead than symlinking the files into webroot directly (as the docs suggest).