Explain this mod_rewrite rule Explain this mod_rewrite rule codeigniter codeigniter

Explain this mod_rewrite rule


The browser sends a request to the server (Apache, since you're using mod_rewrite):

GET profile/edit

Apache accepts this request and sees in its configuration files that you've configured it to pass all requests through mod_rewrite. So, it sends the string 'profile/edit' to mod_rewrite. Mod_rewrite then applies the rules you specified to it, which then transforms the request (in the way I explained in my previous post) to 'index.php/profile/edit'. After mod_rewrite is done, Apache continues processing the request, and sees 'oh, this guy is requesting the file index.php'. So it calls the php interpreter which then parses and executes index.php - and gets '/profile/edit' as arguments. The php code (CI in your case) parses these arguments and knows how to call the right module in your application.

So basically, it's a way to always call index.php, even when the url doesn't specify index.php. In that way, index.php works as the front controller: it routes all requests to the right location in your application.


^ = begin of line( = begin group.* = any character, any number of times) = end group

The $1 in the second part is replaced by the group in the first part.

Is this a Symfony rule? The idea is to pass the whole query string to the index.php (the front controller) as a parameter, so that the front controller can parse and route it.


If the URL does not start with index.php or images or css or js or robots.txt, the string "/index.php/" is prefixed.

As index.php is probably an executable php app, the index.php then can read the rest of the URL from its cgi environment. (it is stored in ${PATH_INFO})