test

CakePHP Note

URL書き換え

UPDATE:2008.04.15

フレンドリーURL

CakePHPはApacheのmod_rewriteエンジンを利用してURLをコントロールし、静的ページ風なURLを実現ています。URLの書き換えに加え、RoutesによるURLマッピングによって最終的にどのコントローラのアクションを駆動するかを決定しています。

一般的なCGIのURL

http://www.yourdomain.com/say_controller.php?param1=hello&param2=world


静的ページ風なURL

http://www.yourdomain.com/say/hello/world

URL書き換え方法

Apacheのmod_rewriteエンジンが利用可能で、.htaccessファイルによる追加設定が利用できるように設定されている必要があります。
webrootディレクトリにある.htaccessファイルの以下のような内容で設定されています。

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>

これは

http://www.yourdomain.com/one/two/three

というアクセスを以下のURLに書き換えます。

http://www.yourdomain.com/index.php?url=/one/two/three


Apacheのmod_rewriteに関しては、Apache module mod_rewrite(URL 書き換えエンジン)Apache URL Rewriting Guide(URL書き換えガイド)で詳しく知る事が出来ます。