Tag Archives: htaccess

Redirecting www To non-www And Vice Versa

Note: This post was written in 2012. The .htaccess rules below still work on Apache servers, but modern setups (NGINX, Caddy, Apache 2.4 with virtual hosts) handle redirects differently. The rules also use http:// — update them to https:// for any SSL-enabled site.

Every domain can be accessed through two different URLs. Take example.com — it’s reachable as both example.com and www.example.com. The same applies to subdomains. From a user’s point of view this doesn’t matter much, but from an SEO standpoint it’s a problem. Having the same content available on two different URLs can be flagged as duplicate content and hurt your search rankings.

Continue reading Redirecting www To non-www And Vice Versa

AddHandler vs AddType : Apache Directive

Note: This post was written in 2012. The core concepts of AddHandler vs AddType are still valid, but modern server setups (NGINX, Apache 2.4+, PHP-FPM) may handle MIME types differently than described here.

Just the other day, while stumbling around the web looking into website branding techniques, I came across something called using custom extensions to brand your website. The topic was interesting enough that I decided to try it myself. My first attempt threw an error — Apache was sending my file straight to the browser as a download instead of executing it server-side. That sent me down a rabbit hole and I landed on something called Apache Directives.

A directive controls how a file is treated by either the client or the server. Once I understood which directive I was supposed to be using, everything started working fine.

AddHandler and AddType are the two directives you’ll deal with most when it comes to file handling. Using the wrong one can break your server or create a security risk.

Continue reading AddHandler vs AddType : Apache Directive