martes, 7 de mayo de 2013

Codeigniter how remove index.php from url

Codeigniter 2.1.3

To remove index.php from url you need to create a .htaccess with this code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /codeigniter
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /codeigniter/index.php
</IfModule>
Modify /codeigniter with your project path.
My project path is /var/www/codeigniter/ so... 
Put it in your project root directory. 
Check if mod_rewrite is enabled. You can create a php file with the next code:
<?php phpinfo(); ?>
and in Loaded Modules section check if is loaded mod_rewrite. Or:
if (in_array('mod_rewrite',apache_get_modules())) {
    echo "mod_rewrite loaded";
} else {
    echo "mod_rewrite not loaded";
}
If mod_rewrite is not loaded
sudo a2enmod rewrite
restart apache
sudo /etc/init.d/apache2 restart
if it doesn't work, you need to enable at least  
AllowOverride FileInfo and Options FollowSymLink 
to your Apache configuration file.
/etc/apache2/sites-available/default

Ok, now you can say good bye to index.php 


No hay comentarios:

Publicar un comentario