CodeIgniter Forums
Routes vs .htaccess - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Routes vs .htaccess (/showthread.php?tid=56542)



Routes vs .htaccess - El Forum - 12-30-2012

[eluser]surfgatinho[/eluser]
Just wondering what the pros and cons of using routes as opposed to mod_rewrite/htaccess might be.

Is either faster? Are there things one can do the other can't, e.g. specify type of redirect (301 etc)?

Thanks


Routes vs .htaccess - El Forum - 12-31-2012

[eluser]Aken[/eluser]
.htaccess will always be faster, because it's processed first before the application. Doesn't mean that you should use it for everything you need, though. Each of them have their time and place to be used.


Routes vs .htaccess - El Forum - 01-02-2013

[eluser]surfgatinho[/eluser]
[quote author="Aken" date="1356939416"]Each of them have their time and place to be used.[/quote]

That's what I was trying to figure out. Any examples / cases where routes might be better than .htaccess.

Thanks


Routes vs .htaccess - El Forum - 01-03-2013

[eluser]Rowan Wilson[/eluser]
It depends what you are trying to achieve, both options have their uses and more than likely you will use both in your application. htaccess is a Web Server configuration file and therefore will be processed before PHP. Routes are a PHP/CI tool that allow you to interact with data in the URL/URI.

Benefits of htaccess are, removing index.php, change apache web server configuration settings, add/remove web server security settings and authentication/authorisation to name but a few. They are also harder to read without consulting the documentation if you ever want to change anything.

Routes are powerful as well from an application point of view. Personally I use them more in Laravel than CI, but CI is still able to do powerful application things like variable passing, RESTful API's, wildcards, intercepting URL's and redirects

HTH