東京うぇ部

PHPをメインにしたプログラム情報共有サイト

CakePHP

CakePHPをサブディレクトリにて運用

CakePHPをサブディレクトリにて運用

CakePHPをサブディレクトリで運用する案件がございましたので備忘録。

http://example.com/test

この場合、testディレクトリにCakePHPを導入するといった件になります。

手順としては以下になります。

まず、testフォルダ(CakePHPを格納したディレクトリ)の.htaccess

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

そして、appディレクトリ直下にある.htaccess

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

最後に、webrootディレクトリ直下にある.htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond  %{REQUEST_FILENAME} !-d
    RewriteCond  %{REQUEST_FILENAME} !-f
    RewriteRule  ^(.*)$ index.php [QSA,L]
    RewriteBase  /test/app/webroot
</IfModule>

これで、testディレクトリでもCakePHPが利用できると思います。

コメントを残す




このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください

関連記事