.htaccess troubleshooting
Published
Updated
Debug .htaccess config problems.
A `.htaccess` problem shows up in two ways. Either every page answers with a 500 error, or the rules have no effect. The Apache error log in the dashboard names the cause of a 500.
500 on every page
Apache stops at the first line it cannot read and answers every request below that folder with 500 Internal Server Error. The Apache error log in the logs of the environment names the file and the directive. Common causes on fortrabbit:
| Error log says | Cause |
|---|---|
Invalid command '…', perhaps misspelled or defined by a module not included | A typo, or a module fortrabbit does not load, such as mod_expires. Wrap module-specific lines in <IfModule> |
… not allowed here | A directive outside the allowed groups, such as <Location>, or Require and AuthType while the dashboard password protection is on |
Option FollowSymLinks not allowed here | Use Options +SymLinksIfOwnerMatch instead |
Rules have no effect
- The file is missing. The leading dot hides it. In macOS Finder,
Cmd + Shift + .shows hidden files. Check that the file is committed in git:git ls-files | grep htaccess. - Wrong folder. The file belongs in the root path, such as
publicorweb, not in the project root above it. - Wrong order.
mod_rewriteruns the rules top to bottom. A framework's front controller rule with[L]ends the processing; place redirects above it. - Browser cache. Browsers cache 301 redirects. Test with
curl -I, which has no cache, or in a private window. - A
.htaccessin a subfolder. When it hasRewriteEngine On, its rules replace those of the parent folder for requests into that subfolder.
Test a rule
curl -sI https://www.example.com/old-page
The status line and the location header show whether a redirect fired. Response headers such as cache-control show up in the same output.
Performance
Apache reads every .htaccess file on the path of a request, on every request. The Apache docs list that as the reason to prefer the server configuration. On fortrabbit, the server configuration is managed, so .htaccess is the place for these rules. Keep the files short and add them only to folders that need them.