Solution:2
Hypertext Access File, or most known as .htaccess
, is a configuration file for Apache web servers that can be used to define very specific configuration options. Configurations can become quite granular with the use of regex however, most users typically stick to using popular .htaccess
examples such as redirecting web pages or setting custom headers.
Although .htaccess
can be quite useful, it can also be somewhat of a challenge to figure out where the issue lies given you are faced with an .htaccess
not working. This post provides a few tips for helping to resolve this issue by identifying a few common .htaccess
problems that you can check in your own .htaccess
file, as well as a few troubleshooting techniques.
Common
.htaccess
problems
#
The following includes a few common .htaccess
problems that are easy to fix and worth trying if you are experiencing issues with your .htaccess
file not working.
.htaccess
needs to be enabled with
AllowOverride
#
This is the first thing that should be verified. If the AllowOverride
directive is set to None
then this will disable all .htaccess
files. In order to verify this, you must open the Apache configuration file (typically either called httpd.conf
or apache.conf
) and check that the AllowOverride
directive is set to AllowOverride All
. If you needed to make changes to your Apache config, remember to save the file and restart Apache.
sudo service apache2 restart
The filename is misspelled or does not begin with a period
#
If you are creating an .htaccess
file from scratch (i.e. you are not using a CMS which comes with an .htaccess
file included) then you must ensure that the filename is correct and that it begins with a period (.
). Without the period at the beginning, Apache will ignore the file – same goes for if the file is misspelled. Additionally, double check that the filename is all lowercase. Your .htaccess
file should be named exactly as .htaccess
.
The location of your rules needs to be above or below others
#
Certain .htaccess
rules may be sensitive to where they are located within the .htaccess
file and therefore cause an .htaccess
not working issue. If upon adding an .htaccess
rule you notice that it is not taking effect, try moving it above the previous rule or to the very beginning of your file.
Conflicting
.htaccess
files
#
Although most users simply use one .htaccess
file, you have the ability to use multiple. Since .htaccess
file rules apply to the directory that they live in, as well as all other subdirectories, it can happen that two or more .htaccess
files are conflicting with one another. To verify this, try disabling each additional .htaccess
file you have one-by-one in order to see where the issue is.
Improper syntax being used
#
It is quite common for a syntax error to be the reason for an .htaccess
file not working. If you are familiar with how to read and configure .htaccess
rules, double check your configuration. Otherwise, you can use the troubleshooting tips mentioned in the next section to help determine why you are experiencing an issue.
How to troubleshoot
.htaccess
not working
#
There are a few options available for troubleshooting an .htaccess
not working. Depending upon the type of issue you are trying to solve, you may need to use a combination of the suggestions mentioned below to determine what steps need to be taken to rectify the issue.
Using an
.htaccess
validator
#
If you’re having issues with the actual syntax of your .htaccess
file, you can run its contents through an .htaccess
validator. The following tools will check your syntax and report back any errors that they find.
- .htaccess Check – This first tool gives you two options for validating your
.htaccess
file. You can either copy and paste the contents of your file directly into the tool or upload an .htaccess
file. The tool will then check your syntax and highlight any lines that it finds errors on.