FuelPHPでindex.phpを省略する方法

fuel/app/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,
+  'index_file' => false,

PROJECT_Directory/public/.htaccessを編集

# Remove index.php from URL
-#RewriteCond %{HTTP:X-Requested-With}    !^XMLHttpRequest$
-#RewriteCond %{THE_REQUEST}                              ^[^/]*/index\.php [NC]
-#RewriteRule ^index\.php(.*)$                    $1 [R=301,NS,L]

# Remove index.php from URL
+RewriteCond %{HTTP:X-Requested-With}    !^XMLHttpRequest$
+RewriteCond %{THE_REQUEST}                              ^[^/]*/index\.php [NC]
+RewriteRule ^index\.php(.*)$                    $1 [R=301,NS,L]

/etc/apache2/apache2.confの先頭に#がついてない全てのAllowOverride NoneのところををAllに変更。

変更が必要ないところもあるので以下をよく確認してください。ずべてコピペはあまりオススメしません。

<Directory />
	Options FollowSymLinks
	AllowOverride All
	Require all denied
</Directory>

<Directory /usr/share/>
	AllowOverride All
	Require all granted
</Directory>

<Directory /var/www/>
	Options Indexes FollowSymLinks
	AllowOverride All
	Require all granted
</Directory>

#<Directory /srv/> //変更する必要なし//
#	Options Indexes FollowSymLinks
#	AllowOverride None
#	Require all granted
#</Directory>




# AccessFileName: The name of the file to look for in each directory
# for additional configuration directives.  See also the AllowOverride
# directive.
#
AccessFileName .htaccess //変更する必要なし//
# 
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
#
<FilesMatch "^\.ht"> //変更する必要なし//
Require all denied
</FilesMatch>

以上の設定をするだけでindex.phpが省略されると書かれていますが自分はそううまくはきませんでした。FuelPHPのバージョンやUbuntuの環境による違いもあると思います。自分のマシンは凝った設定はしておらず、最近Ubuntu Server 16.04.1 LTSをインストールし、EmacsFuelPHPを入れたくらいです。

引き続き/etc/apache2/apache2.confの最終行に以下の設定を加えたらindex.phpを省略できました。

*下記参考サイトではlibexec/apache2/mod_rewrite.soの読み込みを有効にしていますが2016年12月23日時点で自分の環境でsudo findしてもlibexec/apache2/内にmod_rewrite.soは見つかりませんでした。/usr/libexecはなくて/usr/lib/apache2/modules/内にありました。

+LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so 

apacheを再起動するのも忘れずに。(大事)

stnet@m1:$ sudo systemctl restart apache2

参考サイト。

http://qiita.com/cathei/items/a179a2fdb5535e52b180