
Konfigurasi mod_rewrite Code Igniter untuk nginx sebetulnya sangat mudah. Tapi bagaimana caranya menghilangkan index.php dari code igniternya.
Berikut ini adalah caranya.
Pengaturan Nginx
Tambahkan kode ini di block server { .. }.
Biasanya pengaturan nginx ini ada di /etc/nginx/conf.d/ untuk centos versi 6.x atau bisa juga disesuaikan.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
server { server_name domain.tld; root /var/www/codeignitor; index index.html index.php; # set expiration of assets to MAX for caching location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ { expires max; log_not_found off; } location / { # Check if a file or directory index file exists, else route it to index.php. try_files $uri $uri / /index.php; } location ~* \.php$ { fastcgi_pass 127.0.0.1:9000; include fastcgi.conf; } } |
Kemudian untuk pengaturan konfigurasi di Code Igniter-nya adalah sebagai berikut:
1 2 3 |
$config [ 'index_page' ] = "" ; $config [ 'uri_protocol' ] = "REQUEST_URI" ; |
Hilangkan index.php dibagian index page.
Demikian. Semoga membantu.