Solusi Problem mod_rewrite CodeIgniter

Beberapa aplikasi yang saya bikin mengunakan framework CodeIgniter rupanya sedikit bermasalah ketika saya mengimplementasikan mod_rewrite untuk mempercantik permalink. Problem ini rupanya disebabkan oleh faktor hosting yang entah kenapa konfigurasinya agak nyleneh ketika menggunakan CI (padahal kalo tidak pake CI, mod_rewrite tidak bermasalah).

Selidik pupnya selidik rupanya masalah ini terjadi di beberapa hosting. Untuk mengatasinya rupanya ada hal yang perlu dioprek, baik dari .htaccess (saya menggunakan shared hosting, sehingga pengaturan dilakukan melalui .htaccess) dan file config.php di CI-nya.

Sebelumnya, untuk membuat permalink yang cantik di CI, silakan baca tutorialnya dulu. Jika ternyata cara ini gagal, marilah kita oprek.

Pastikan isi file .htaccess seperti berikut:

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

Isi file .htaccess ini agak berbeda dari manual, karena saya memilih mengabaikan kondisi rewrite bila alamat yang diminta adalah file (perintah RewriteCond %{REQUEST_FILENAME} !-f dan direktori (melalui perintah RewriteCond %{REQUEST_FILENAME} !-d).

Sunting file config.php yang ada di folder application/config, kemudian ubah pada bagian ini:

/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
|
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
|
*/
$config['index_page'] = "index.php";

/*
|--------------------------------------------------------------------------
| URI PROTOCOL
|--------------------------------------------------------------------------
|
| This item determines which server global should be used to retrieve the
| URI string.  The default setting of "AUTO" works for most servers.
| If your links do not seem to work, try one of the other delicious flavors:
|
| 'AUTO'		Default - auto detects
| 'PATH_INFO'		Uses the PATH_INFO
| 'QUERY_STRING'	Uses the QUERY_STRING
| 'REQUEST_URI'		Uses the REQUEST_URI
| 'ORIG_PATH_INFO'	Uses the ORIG_PATH_INFO
|
*/
$config['uri_protocol']	= "AUTO";

Menjadi:

/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
|
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
|
*/
$config['index_page'] = "";

/*
|--------------------------------------------------------------------------
| URI PROTOCOL
|--------------------------------------------------------------------------
|
| This item determines which server global should be used to retrieve the
| URI string.  The default setting of "AUTO" works for most servers.
| If your links do not seem to work, try one of the other delicious flavors:
|
| 'AUTO'		Default - auto detects
| 'PATH_INFO'		Uses the PATH_INFO
| 'QUERY_STRING'	Uses the QUERY_STRING
| 'REQUEST_URI'		Uses the REQUEST_URI
| 'ORIG_PATH_INFO'	Uses the ORIG_PATH_INFO
|
*/
$config['uri_protocol']	= "REQUEST_URI";

Selesai! Kini seharusnya permalink sudah cantik dengan tanpa menampilkan index.php di URL. (banana_cool)

Related Articles

4 responses

  1.  

    hora mudeng (worship)

    geblek — October 3, 2009 17:15
  2.  

    Wuih, pakainya Code Igniter toh, diriku pikir ZEND atau CakePHP. :D

    mawi wijna — October 4, 2009 18:38
  3.  

    aku juga kirain pake CakePHP (thinking)

    oCHa — October 6, 2009 02:17
  4.  

    masih blm bisa di server ku bos… :(

    padahal mod_rewrite dah aktif, tapi dia masih aja ga mau jalan klo ga pake index.php

    knp ya? :-&

    arioss — November 19, 2009 15:52
 
:-)) :-) :-D :-P (woot) ;-) :-o X-( :-( :-& (angry) (annoyed) (bye) B-) (cozy) (sick) (: (goodluck) (griltongue) (mmm) (hungry) (music) (tears) (tongue) (unsure) (dance) (doh) (brokenheart) (drinking) (girlkiss) (rofl) (money) (rock) (nottalking) (party) (sleeping) (thinking) (bringit) (worship) (applause) 8-) (gym) (heart) (devil) (lmao) (banana_cool) (banana_rock) (evil_grin) (headspin) (heart_beat) (ninja) (haha) (evilsmirk) (bigeyes) (funkydance) (idiot) (lonely) (scenic) (hassle) (panic) (okok) (yahoo) (K) (highfive) (LOL) (blush) (taser)