What to Do When .htaccess Doesn't Work or Has No Effect
Overview
This is about what to do when things don’t behave as configured in your .htaccess, or when it looks like the file isn’t being read at all.
For cases like “mod_rewrite redirects work over http but not over https,”
most common misconfiguration patterns can be resolved by checking the following basics.
Test Environment
- CentOS 6.6 (Final)
- Apache/2.2.15(Unix)
What You Need in Order to Use .htaccess at All
You need the following directive in a configuration file such as /etc/httpd/conf/httpd.conf.
1 | AllowOverride All |
What You Need in Order to Use mod_rewrite
To use mod_rewrite, which is used very frequently, you need the following.
1. Install mod_rewrite.so
2. Load mod_rewrite.so from the Apache configuration file
Let’s start by checking the above.
1. Verify mod_rewrite.so Is Installed
With Apache, it’s usually stored under the modules directory.
1 | $ ls -al /etc/httpd/modules/mod_rewrite.so |
2. Verify mod_rewrite.so Is Loaded from the Apache Configuration File
In an Apache configuration file such as/etc/httpd/conf/httpd.conf or /etc/httpd/conf.d/*.conf, the following is configured.
- Note: In some environments the configuration file is not placed in
/etc/httpd/conf/httpd.conf,
so treat this as a general example only.
1 | LoadModule rewrite_module modules/mod_rewrite.so |
Additional Notes
The module-loading configuration usually hasAllowOverride All set within a <Directory> directive, like the following.
In the example below, under the “/var/www/html” directory, the .htaccess you place there takes priority for configuration.
1 | <Directory "/var/www/html"> |
In the unlikely event that the mod_rewrite.so module does not exist, you will need to recompile Apache.
Installing mod_rewrite into Apache and Recompiling
- Recompile and restart Apache.
1 | $ sudo su - |
That’s all.

