Usually when we run a CodeIgniter website, the url will have index.php after the hostname. To remove this we need to use mode_rewrite, htaccess.
First just check your php info of your server whether you have loded mod_rewrite module. To check this create 'php-info.php' file and put the following contents and run it.
php-info.php
<?php
echo phpinfo();
?>
In your output, check whether in loaded modules 'mod_rewrite' is enabled or not.
If its enabled as given above, You are ready to use '.htaccess'. Otherwise you need to load the module in your server.
To remove 'index.php' from the url, create a '.htaccess' file ( no file name, just '.htaccess') in the root directory of your website where 'index.php' file of the codeigniter resides. And write the followin contents...
.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /example.com/index.php/$1
The above code is to rewrite the url 'http://localhost/example.com/<something>' to 'http://localhost/example.com/index.php/<something>' except for folders and files.
If your website url is in the root of the server like 'http://example.com/index.php/<something>'. To use this like 'http://example.com/<something>' , The htaccess code in the Line 4 should be like 'RewriteRule ^(.*)$ /index.php/$1'.
No comments:
Post a Comment