Menghapus index.php CodeIgniter 3 di Server Apache2 Ubuntu

Menghapus index.php CodeIgniter 3 di Server Apache2 Ubuntu

Published on 31 Jul 2018 | Takes approximately 1 min to read

Tulisan kali ini singkat saja. Sebagai catatan diri sendiri dan jika ada yang membutuhkannya. Menjelaskan tahapan-tahapan menghapus index.php pada Framework PHP CodeIgniter 3.

Membuat file .htaccess

Pertama, buatlah file .htaccess di folder root.

Isi dengan kode di bawah.

.htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_URI} ^/system.*
    RewriteRule ^(.*)$ index.php?/$1 [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)$ index.php?/$1 [L]
    ErrorDocument 404 index.php
</IfModule>
Save file.

Mengatur file config.php

Buka file config.php di folder application/config.

Hapus index.php di

$config['index_page'] = '';
Lalu Save.

Tambahan: Untuk Server Baru

Buka terminal.

Pertama, aktifkan modul rewrite di server dengan mengetikkan command berikut.

$ sudo a2enmod rewrite
Lalu, restart apache service.
$ sudo service apache2 restart
Masuk dan edit file apache2.conf dengan mengetik perintah berikut.
$ sudo nano /etc/apache2/apache2.conf
Periksa dan pastikan AllowOverride bernilai All. Jika belum silakan diubah.
<Directory "/var/www">
  AllowOverride All
</Directory>
Selesai.

Sekarang cek web anda. Terimakasih.