[CakePHP2.x] .htaccessのRwriteEngineなどの設定

CakePHP2.x CentOS の環境の 「.htaccess」設定方法です。

RewriteEngineの設定を行い、ベーシック認証もかけるようにしてみます。
「/var/www/html/sample」というディレクトリにCakePHPの公開ファイルを設置します。(index.phpや.htaccessなど)
「mypassword」ディレクトリにはベーシック認証用のIDとPASSWORDが記載された「htpasswd」ファイルを設置しておきます。

.htaccess

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

//ベーシック認証の設定
<Files ~ "^\.(htaccess|htpasswd)$">
deny from all
</Files>
Options -Indexes
AuthUserFile /mypassword/htpasswd
AuthGroupFile /dev/null
AuthName "Please enter your ID and password"
AuthType Basic
require valid-user 
order deny,allow

これでCakePHPが動き、ベーシック認証も動くようになります。



Author: webmaster