- 2008-06-26 (木) 21:19
- CakePHP
この記事の所要時間: 約 1分21秒
CakePHPでは[app/webroot/index.php]がFront Controllerになっているのですが、これを他のファイル名に変える方法です。(DocumentRootがapp/webrootになっている場合)
1. index.phpを他のファイル名に変更
ここではgw.phpをFront Controllerにします。
$ mv index.php gw.php
2. .htaccessを変更
あとはapp/webroot/.htaccessのRewriteRuleを変更すればokです。
<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f # RewriteRule ^(.*)$ index.php?url=$1 [QSA,L] RewriteRule ^(.*)$ gw.php?url=$1 [QSA,L] </IfModule>
index.phpはフレームワークを避けるとか
これは以前index.phpだけはデザイナーさんが自由に使いたいという要望があったため考えました。(もちろんPagesControllerを使っても良いのですが)
index.phpはサイトのトップページになることが多いので、アクセスによる負荷を考えて、あえてフレームワークを避けるという手にも使えますね。
- Newer: 第3回CakePHP勉強会も盛り上がりました。
- Older: 第3回CakePHP勉強会&第34回PHP勉強会に参加します
トラックバック:0
- このエントリーのトラックバックURL
- /blog/2008/06/cakephp_front_controller_file.html/trackback
- Listed below are links to weblogs that reference
- CakePHP index.php以外からフレームワークを使う from Shin x blog