[Share] How to remove ‘/index.php’ from codeigniter url
Secara defaultnya apabila kita menggunakan framework codeigniter, url nya sebagai berikut : http://localhost//index.php// . nah untuk mempersingkat url tersebut (menghilangkan /index.php langkah-langkahnya sebagai berikut :
1. Aktifkan module rewrite di apache server dengan cara sebagai berikut :
sudo a2enmod rewrite
2. edit file di folder /etc/apache2/sites-available/default :
sudo gedit /etc/apache2/sites-available/default
cari baris berikut ini :
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
# This directive allows us to have apache2′s default start page
# in /apache2-default/, but still have / go to the right place
# Commented out for Ubuntu
#RedirectMatch ^/$ /apache2-default/
ubah “None” pada AllowOverride menjadi “All” (tanpa tanda kutip) lalu save dan exit.
3. edit config.php di application/config/config.php, cari baris $config['index_page'] = “index.php”; lalu ganti menjadi $config['index_page'] = “”;
4. create file .htaccess pada root application codeigniter lalu copy paste code berikut ini :
RewriteEngine On
RewriteBase /#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#’system’ can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]#When your application folder isn’t in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename ‘application’ to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn’t true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]# If we don’t have mod_rewrite installed, all 404′s
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughinErrorDocument 404 /index.php
5. restart apache
sudo /etc/init.d/apache2 restart
dan lihatlah hasilnya…
Semoga bermanfaat…..Happy Coding….^_^