Apache ignores your .htaccess file
Redirect and rewrite rules in .htaccess have no effectShort answer
Apache ignores .htaccess when AllowOverride is None, which is its default. Add AllowOverride All (or FileInfo for rewrites) inside the Directory block of your site and reload. If rewrites still fail, turn on RewriteEngine and make sure the module is loaded.
Fix it fast
1Find out which cause you have
Put one nonsense word in the .htaccess file and load the page. A 500 error means the file is read. A normal page means Apache ignores it.
echo "TestMe" >> /var/www/example/.htaccess curl -I http://example.com/2Match what you see, then jump to its fix
- 1
The test word gives no error and the page loads as before.AllowOverride is None for that directoryFix - 2
The error log says a directive is "not allowed here".AllowOverride is on, but too narrow for the directive you usedFix - 3
Other .htaccess directives work, but RewriteRule lines do nothing.Rewrite rules need the engine on and FollowSymLinksFix
- 1
What does the error look like?
Redirect and rewrite rules in .htaccess have no effect500 Internal Server Error after editing .htaccess.htaccess: DirectoryIndex not allowed here
Cause 1 of 3
AllowOverride is None for that directory
1Check
The default is AllowOverride None, which makes Apache skip .htaccess files. Look for the setting in your site config.
grep -R -n -A3 "<Directory" /etc/apache2/ | grep -i -E 'Directory|AllowOverride'2Fix
In the Directory block that covers your site, allow overrides, then reload Apache.
<Directory "/var/www/example">
AllowOverride All
</Directory>3Verify
Test the config, reload, and repeat the nonsense-word test. It must now return 500. Remove the word afterwards.
sudo apachectl configtest && sudo systemctl reload apache2
curl -I http://example.com/Confirmed by httpd.apache.org
Cause 2 of 3
AllowOverride is on, but too narrow for the directive you used
1Check
Each directive belongs to an override group. RewriteRule, Redirect, Header and ErrorDocument need FileInfo. Read the log line, then the directive's Override entry in the docs.
sudo tail -n 20 /var/log/apache2/error.log2Fix
Grant the group the directive needs, or list single directives with AllowOverrideList.
<Directory "/var/www/example">
AllowOverride FileInfo
# or: AllowOverride None
# AllowOverrideList Redirect RedirectMatch
</Directory>3Verify
Reload and repeat the request. The 'not allowed here' line must stop appearing.
sudo apachectl configtest && sudo systemctl reload apache2Confirmed by httpd.apache.org
Cause 3 of 3
Rewrite rules need the engine on and FollowSymLinks
1Check
Rewriting is off by default (RewriteEngine off) and, in .htaccess, also needs FollowSymLinks or SymLinksIfOwnerMatch allowed in the server configuration.
apachectl -M | grep rewrite
head -n 5 /var/www/example/.htaccess2Fix
Load the module, set the engine on in the .htaccess file, and permit the options in the Directory block.
# server config
LoadModule rewrite_module modules/mod_rewrite.so
<Directory "/var/www/example">
AllowOverride FileInfo
Options +FollowSymLinks
</Directory>
# .htaccess
RewriteEngine On
RewriteRule ^old-page\.html$ /new-page.html [R=301,L]3Verify
Reload Apache and request the old URL.
curl -I http://example.com/old-page.htmlConfirmed by httpd.apache.org
How do I stop it coming back?
- Keep rules in the main server config when you can; Apache reads it once at start instead of on every request.
- Change one directive at a time and read the error log after each reload.
- Allow only the override group you need, not All, on shared servers.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Related fixes
Servers
dnf cannot install MySQL on Amazon Linux 2023
dnf cannot find a mysql-server package on Amazon Linux 2023
Amazon Linux 2023 documents MariaDB, not MySQL, as its database server, with packages named mariadb105 and mariadb105-server.
3 causes, each with a fixServers
Ansible hangs, then times out waiting for the sudo prompt
a playbook using become seems to hang
Ansible ran sudo on the target and never saw the answer it expected.
3 causes, each with a fixServers
Apache on Ubuntu returns 404 Not Found for my site
The requested URL was not found on this server.
On Ubuntu a 404 from Apache usually means the request maps to a path that has no file.
3 causes, each with a fixServers
Apache returns 504 Gateway Timeout when PHP takes too long
Quick requests work, slow ones end in a 504 after a fixed wait
A 504 from Apache means the backend did not answer within the proxy timeout.
2 causes, each with a fixServers
Apache logs SIGWINCH and exits on its own
the httpd container stops although nothing crashed
SIGWINCH is Apache's graceful-stop signal.
2 causes, each with a fixServers
Apache warns that a ${VAR} config variable is not defined
${VAR} left unchanged in the configuration, with a warning in the error log
Apache expands ${VAR} from Define or from the shell environment that exists when the server starts.
3 causes, each with a fix