URL setup in CodeIgniter
We explained the basic setup of CodeIgniter in the previous article. Now, in this article, I will be explaining the URL setup in CodeIgniter.
As a matter of fact, URLs in CodeIgniter are intended to be internet searchable and human-understandable. As opposed to utilizing the “query string” way to deal with URLs that is synonymous with dynamic frameworks, CodeIgniter uses a fragment-based methodology:
Here is the explanation for URI segments:
The controller represents the first portion.
The second portion contains the called function.
Any other portion are the variables which controller parses.
Disabling index.php file
MVC structure already contains this file.
You can remove this by using .htaccess file. It can be done by using rules if mode_rewrite is enabled in the Apache server.
Note: All servers might not support these rules set in the file.
Use of query strings
In some scenarios you can use query strings which can be set in application/config.php file:
Following code is in the config file:
$config[‘enable_query_strings’] = FALSE;
$config[‘controller_trigger’] = ‘q’;
$config[‘function_trigger’] = ‘n’
For eg: index.php?q=controller&n=method
Using the above code you can now create clean URLs.
Share your views/queries in comments.
I am Sr. Software Developer having more then 6 years of experience.