Finding, Creating, and Editing .htaccess files

.htaccess is amazing! If you haven’t read the introduction to .htaccess, check that out first (Unless you already know the amazing things .htaccess can do). Remember that .htaccess files are used only on Apache web servers.

How to create a .htaccess file

Creating a .htaccess file can be tricky, as some systems don’t want the name to start with a dot. For example, Chrome OS and Windows do not allow it at all! Fortunately, your FTP software allows it, and that is all that matters. Once you create the file in your FTP software, you can download it to your computer and edit it there (Sometimes, however, the system still won’t like it. For example, Chrome OS removes the dot, making it useless). The solution? Build your .htaccess file on your computer, but name it “htaccess.txt”. After you are done creating or editing it, upload it to your web server, then rename it to “.htaccess”.
IMPORTANT! Permissions for .htaccess files must be set to 755. Check your CHMOD settings if your .htaccess is not working properly.
Many systems don’t allow filenames starting with a dot, so that restricts how we can create a .htaccess file. We can get around it though, so here are the steps again in case you missed them, or got confused.

  1. Open your text-editing program and create or edit your .htaccess file
  2. Once you are finished, save it as “htaccess.txt” to your computer
  3. Upload “htaccess.txt” to your webserver and rename it to “.htaccess” (Remember that the dot is important!)

Note: An .htaccess file located in a sub-directory overrides any duplicate rules from previous .htaccess files. For example, if you have a .htaccess file located in the root defining a 404 and 403 error page, and another .htaccess located in the “test” folder defining only a 404 error page, any files and folders in the “test” folder will use the 404 page defined in the "test" .htaccess file, and the 403 page defined in the root .htaccess file.


How to edit a .htaccess file

Just like creating a .htaccess file, sometimes you have to get around restrictions (If you're lucky enough to not run into any, just download the file, edit it, then re-upload it!). If you need to edit it, and files starting with a dot are restricted by your OS, remember to rename it back to “htaccess.txt” before downloading! Here are the steps again, just in case you got confused.

  1. Rename the file to “htaccess.txt” while the file is still on the server
  2. Dowload the renamed file onto your computer
  3. Make any edits you want by opening the file on your computer
  4. After you make your edits, upload the fale back to the server, replacing the file currently there
  5. Rename the file on the server to “.htaccess”


Now that we have the basics out of the way, we can start building! Visit the list of things you can do with .htaccess to get started, or get started by setting up your custom error pages. Have fun!


Article by Tinkerman