機械系大学生の修行ログ

sh-lu0's Tech Blog

アイドルが力をくれる

CodeIgniterのURLからindex.phpを削除する

.htaccess追加

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

RewriteEngine:Apacheのモジュールであるmod_rewriteを利用するときに使う宣言文
RewriteEngine onでmod_rewrite(URL書き換えエンジン)を有効にする。

【mod_rewrite】 RewriteEngineとは? – mod rewrite

注意

デフォルトで、application/.htaccessに設置されていたが
applicationと同じ階層に移動させる。

httpd.conf

仮想環境上でApachの設定を変更する。

vi /etc/httpd/conf/httpd.conf

.htaccessの設定を有効にする

AllowOverride None
↓
AllowOverride All

[Apache] Options と AllowOverRide の設定値を改めて整理してみる | バシャログ。

mod_rewriteコメントアウトを解除

#LoadModule rewrite_module modules/mod_rewrite.so
↓
LoadModule rewrite_module modules/mod_rewrite.so

CodeIgniterのconfig.php

$config['index_page'] = 'index.php';
↓
$config['index_page'] = '';

apache再起動

systemctl reload httpd

参考URL

CodeIgniter URLs — CodeIgniter 3.1.10 documentation