Greg Aker

What's Your .htaccess?

I don't use a whole lot of Apache anymore for my personal stuff, but when I do, here's my basic .htaccess.

Some people might say:

"Woah Greg, what the heck, you aren't gzipping your static content you hosehead!"

Well, I have an answer for you. See, gzipping can be a CPU-intensive operation on the web servers. If you're on a Cheap VPS, a la Linode, Rackspace Cloud, Slicehost, etc you're trying to squeeze every bit of CPU power out of it. Or on the flip side, an awesome host like EngineHosting (yes, I do work there. :) ) is gzipping content at the Load Balancers, so you're not going to be beating up on the web servers. Make sense?

Another couple things to note, I generally don't bother with the 'Include' or 'Exclude' methods listed on the ExpressionEngine Wiki. Unless I have a situation where I can see Apache being affected by using the File & Directory check method, I think it's a pain in the butt to keep track of everything in the .htaccess, and mistakes can happen.

A couple points:
FileETag NoneThis unsets ETags, which is a header attached to your content by Apache. For more information on ETags, read about it. I'm choosing to either force www, or remove www. I generally choose to force it. If it's good enough for our favorite search engine, it's good enough for me.

ExpiresByType - The websites are dynamic, but the static resources probably don't change all that much. So we tell the browser to cache the html page itself for 1 second, and send a 1 month caching header on everything else.

Now, I do realize that Yahoo and Google say to do it longer, but I am asserting that for websites like us, it does not matter. We don't, nor will we probably ever pull 1/1000th of the traffic of those sites. It's not very likely that someone is going to still have images from our website in their cache 5-6 weeks from now. With Yahoo or Google, that's a different story.n So really, I could probably get away with a week or even a day here, but you get the general point. :)

I find this .htaccess to be solid for me on CodeIgniter, WordPress, ExpressionEngine or Zend Framework projects.So what do you do?