• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Routes vs .htaccess

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)?


.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.

[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.


[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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.