views:

41

answers:

2

If our .htaccess files are purely for mod rewrites, is there a security / development downside to committing .htaccess files alongside other files in your repository?

For various reasons (our SEO optimisers like to add pretty urls as new promotions occur, etc) we need a fair few rewrite rules inside these files. Would I be better off pushing the routing into php-land and dealing with it there? Or is reading from a .htaccess via apache fine?

The .htaccess files are not exposed via the web server, so that's not a security risk.

A: 

As I recall, once you use one .htaccess file, you already have agreed to pay the price, that price being apache will look all over the place, every request, for .htaccess files. That's a performance issue though.

I think your ideal solution is to not use .htaccess files at all, but set those rules in httpd.conf. PHP is not better at redirection than apache, so no help there. That's the performance answer. Develop however feels best, and then for production move the rules into the server core.

As for version control, if it is a file full of text, that is needed for the code, then yes, I would put it into version control. I'd do that right now in fact. If many people are adding in their own redirect rules in .htaccess files all over the place, you'll want to be able to:

  1. Roll back the changes.
  2. Point the finger! ;)
chiggsy
It's *slightly* more complex than that - we have a CMS which writes rewrite rules into .htaccess files - this is so that the SEO guys can add pretty urls. Could be bad business process but it's how it's currently done... so that may rule out httpd.confThe routing via php is how most frameworks do it now, ie. pass through a generic catch-all rewrite that then determines the correct route based on php rules. (ie. codeigniters 'routes.php')
Rob
A: 

.htaccess mod_rewrite is waaaaaay faster than routing things on the php side, i would stick with mod_rewrite for url manipulation

David Morrow
more and more frameworks are shifting into a scripting environment routing engine, you can't do MVC that well without it, which is the direction I am trying to push the project into. I agree that vanilla PHP would be slower but it's likely that memcache style caching could parallel or even be faster than apache's continual file access for every request (disk caching might nullify that though). Given that the cms is taking client-entered (unsafe) content and writing it out to config files... exceptions occur in the apache land not php land, which may not be as recoverable and isn't as flexible.
Rob