.htaccess files
As promised, I'm going to cover the .htaccess file with this post. Now, obviously I've had a few rounds with this subject, but I felt it was going to be pretty important that I do some research to ensure I know what I'm talking about and make sure I cover the subject quickly, but adequately. So not all over these words are directly mine, but a result of looking up the subject of the mighty .htaccess file.
The .htaccess file is a configuration file used by web servers running Apache software. It sets many of "the rules" for your server. The most common use for the file is website redirects (such as my case where I wanted to redirect any HTTP request to HTTPS, the secure site) and improve security. In shared hosting (a common hosting option), you will put your .htaccess file in the main, or root, directory. Something I've just learned: the name stands for "hypertext access," and it can control some really important aspects of how your website interacts with a visitor's browser.
Now, let me pause real quick and cover something else that I did not really know up until tonight. Let's go back to the first sentence of that last paragraph (don't really go back, keep reading, just think back), the one that says "used by web servers running Apache software." In school we were taught on the LAMP stack (Linux, Apache, MySQL, PHP), so I had seen a .htaccess file in every webpage that I had put up. I didn't put them there, it was one of those 'magically there' things - it just 'was.' And with school focusing solely on the LAMP stack, I've never used Nginx. As a matter of fact, I've only known that it was pronounced "engine x" for the past few weeks. So I had no idea how Nginx worked. Learning that it does not use .htaccess, but instead covers the issues in the main configuration file or in specific server block files, was interesting. I went down a small rabbit hole, but had to pull myself out fairly quickly to complete this post. From what I read, this put Nginx in the "steeper learning curve" category, but offsets the pain with a streamlined way to manage your server configurations.
So obviously not all .htaccess files are created equally and mine wanted to be a unique butterfly. I wrote so many configurations of the same thing that "doing something over and over and expecting a different result" might apply in this situation. Thing is, I learned a ton. And I learned that, yes, there is an article in Liquid Web's documentation that correctly demonstrates the solution to my problem. It's a lot easier to search for something when you already know the outcome. So if you are using Apache, this little file is a powerful tool and it is really important to work out the specific requirements for your server. The nice thing is, once you know...you have the power in your hands.
And that being said, I'm going to move to yet another direction. I guess I should have realized that Nginx would not necessarily use .htaccess files, as I had already discovered that Caddy doesn't use them either. This very website that you are reading is running on Caddy rather than Apache or Nginx, and let me tell you...Caddy? It just works. Well, that might be a little disingenuous considering I'm stealing that "it just works" from many, many online discussions about Caddy, but everyone seems to have the same opinion. And also disingenuous because I became convinced fairly quickly, but not immediately. What? Why not immediately? Oh, in the "stuff they don't teach" category, even on a VPS where many customers are quite likely using it to host websites, you still have to "ufw allow 80" and "ufw allow 443" (Linux commands to open ports). Yeah, open the ports that are used to make HTTP and HTTPS requests dummy! Nothing, not even Caddy, is going to work on a website until you open those ports! It makes me smile now, I'm learning.
Posted on: 2024-07-04 02:56:58.163408