Everything a web designer needs to need to know about .htaccess

By Geoff Muskett

Note: this post won’t actually teach you much about .htaccess, it will simply point you to where you can find more info and snippets to copy and paste. If you actually want to learn about it and how to start coding .htaccess I’d suggest this post on nettuts.

I’d recently decided to use geoffmuskett.com as my primary address as opposed to geoffmuskett.co.uk because for my line of work I’d rather not be location specific, even though the domain extension doesn’t really make a lot of difference with search engines. There’s a few links coming into the site, all to the .co.uk domain, and I want to maintain those precious little search engine boosters.

In addition to this I want to root www.geoffmuskett.co.uk to geoffmuskett.com. It doesn’t make any difference either way, but it’s just quicker not to type www. Every site should choose one or the other so search engines don’t see two versions.

Both these adjustments point to one thing…

The dreaded .htaccess file

Honestly, not my specialist subject. Luckily HTML5 boilerplate has a super userful .htaccess file. There’s loads in there, 301 redirect for www to not www is just one of them. Amongst the most uesful there’s gzipping, which has an awesome effect on performance, and rules for leveraging browser caching.

So go download html5 Boilerplate and rip out what you need, while sending happy thoughts to Nicolas GallagherPaul IrishMathias BynensDivya Manian, and Hans Christian Reinl.

.co.uk to .com 301 redirect

This is the only thing missing from the boilerplate .htaccess file. Another permanent 301 redirect is the answer, here’s the snippet…

RewriteCond %{HTTP_HOST} ^geoffmuskett.co.uk$ [NC]
RewriteRule ^(.*)$ http://geoffmuskett.com/$1 [L,R=301]

This would of course work for whateverdomain.com to somethingorother.com, which is good to preserve the SEO you’ve built up on whateverdomain.com. According to the search Messiah, Matt Cutts, You can get away with 3 or 4 redirects until Google stops transferring the healthy link juice.

Should a web designer learn to code .htaccess?

This goes against what I’d usually say, but no, to be honest a web designer doesn’t need to learn everything there is to know about hand-crafting .htaccess files. He or she should just know where to get the snippets needed to do a specific job, it’s rare that anything comes up which requires deeper knowledge, when it does ask an expert!

Web designers should spend as much time as they can, doing what they do best, designing websites.

Comments

Leave a Reply

Your email address will not be published.

Join my newsletter

If you’re looking for insights into web design and development, and crafting a successful presence online, then you should join the smart folk on on my newsletter. I discuss my thoughts on an issue relating to the web, then provide and teach effective solutions.