Welcome Guest, Not a member yet? Register   Sign In
Routes vs .htaccess
#1

[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
#2

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

[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
#4

[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




Theme © iAndrew 2016 - Forum software by © MyBB