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.
- Open your text-editing program and create or edit your .htaccess file
- Once you are finished, save it as “htaccess.txt” to your computer
- 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.
- Rename the file to “htaccess.txt” while the file is still on the server
- Dowload the renamed file onto your computer
- Make any edits you want by opening the file on your computer
- After you make your edits, upload the fale back to the server, replacing the file currently there
- Rename the file on the server to “.htaccess”