If you’ve ever spent any real time working with WordPress there’s a fairly good chance you’ve run across a strange file in the root (or topmost) directory. Whereas the vast majority of the files comprising the WordPress hierarchy consist of a filename and an extension, such as the crucial wp-config.php, one single file seems a bit out of place. That file is the aptly-named .htaccess file. So just what is the .htaccess file?
First, a bit of history. The name itself is fairly self-explanatory. The ht in the name stands for “hypertext”, and access… well, that part shouldn’t have to be explained. So the original purpose of the .htaccess file was to provide directory-level control to content on an Apache server. And what about that weird dot? Well, the Apache web server was originally built for POSIX-based systems (UNIX, Linux and similar). On POSIX-based systems, prefixing a filename with a dot marks it as a “hidden” file. As the .htaccess file was created as an advanced configuration file, its presence didn’t need to be known to end users. Accidentally deleting it could potentially cause all sorts of issues!
Taking a step forward in time, today the .htaccess file read by several web servers including Apache (duh), the Sun Java System web server, and even Microsoft’s IIS. However, not all servers are created equally. One of the more popular servers in use today is NGINX, which does not support .htaccess files. Additionally, while initially intended for use on POSIX-based system, it certainly isn’t restricted to them; after all, we just mentioned that the Windows IIS web server supports .htaccess!
Oh yea… and today, the .htaccess file isn’t confined to simple directory access. These days, it supports a subset of the global server configuration (using the Apache ruleset, regardless of the actual server in use). Today, you can do anything from restricting access to files or directories, through image hotlinking preventions, and even advanced redirects.
But what’s going on with the WordPress .htaccess file?
When you initially setup WordPress, a minimal .htaccess file is created for you that looks something like this:
Copy to Clipboard
Well now… that looks confusing… But it’s not. The first and last lines (aside from the comments) perform a quick check to ensure that the mod_rewrite module is enabled on the server. If it isn’t, none of the included rules are run. The included rewrite rules take a bit more explaining.
Copy to Clipboard
See? Not so difficult!
So what else can you do with these rewrite rules? Quite a bit! So much so that we aren’t going to cover them all here. For the moment, we’re going to leave you with a few useful resources which can give you a head start to understanding .htaccess and regular expressions, and an excellent article on tweaking the WordPress .htaccess file. Enjoy, and happy learning!
n. One who is always learning; a compound derived from ever and tiro
Admittedly, the above word is not in any actual dictionary. In fact, to my knowledge, I am the first person ever to combine those two words. At the very least, an Internet search revealed no other known uses of the combination. But the idea is paramount to a significant change in my life that began in early 2017.
In short, I’m planning on converting a bus to an RV. Truthfully there’s a significant learning curve to converting a bus, but that’s the whole idea behind Evertiro. I came up with the word Evertiro while researching bus conversions after realizing that I had a lot to learn. Fortunately, I have no shortage of friends who have the necessary skills and have volunteered to help!