はじめに
こんにちは、スマートな「さいとうさん」です!
URLってスマートだとかっこいいですよね。
そこで、FuelPHPで長くなりがちなURLを......
http://localhost/blog/public/index.php/welcome
から
/index.phpを取り除き…
http://localhost/blog/public/welcome
こんなスマートなURLにする方法をお伝えします!
※ちなみにFuelPHPのversionは1.7です。
※http://localhost/blog/public/index.php/welcome
このURLのblogと書いてある部分は自身のプロジェクト名です。
index_fileをfalseにする
config.phpファイルに変更すべき箇所があります。
APPPATH/config/config.php
/**
* index_file - The name of the main bootstrap file.
*
* Set this to 'index.php if you don't use URL rewriting
*/
// ↓コメントアウトされてるところ!↓
// 'index_file' => false,
コメントアウトされているので有効にします。
APPPATH/config/config.php
/**
* index_file - The name of the main bootstrap file.
*
* Set this to 'index.php if you don't use URL rewriting
*/
// ↓コメントを外してあげる!↓
'index_file' => false,
httpd.confの設定
※(僕のファイルはここにありました)
/etc/apache2/httpd.conf
<Directory "/Users/naoki/fuelphp/blog/public">
・・・
・・・
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
# None になっているところを変更する
AllowOverride None
・・・
・・・
</Directory>
None になっているところを All に変更する
/etc/apache2/httpd.conf
<Directory "/Users/naoki/fuelphp/blog/public">
・・・
・・・
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
# All に変更!
AllowOverride All
・・・
・・・
</Directory>
最後に
apacheに設定変更を反映させるので、下記のコマンドを実行する。
sudo apachectl restart
コマンド実行したらURLにアクセス!
http://localhost/blog/public/welcome
これで設定完了!スマート!!
Qiitaで、さいとうさんが書いた記事はこちら。