.htaccess intro

Published

Updated

Apache web server configuration via .htaccess.

fortrabbit runs the Apache 2.4 web server, and Apache reads `.htaccess` files in the code. Use them for redirects, access rules, compression and HTTP headers. The Apache configuration itself is managed by fortrabbit.

Where the file goes

A .htaccess file applies to its own folder and every folder below it. The main one sits in the root path of the environment, for example public for Laravel or web for Craft CMS. Commit it with the code and it deploys with every git push.

The leading dot makes the file hidden in most file managers. A missing .htaccess is a common cause of 404 errors, see troubleshooting.

What the platform sets

SettingOn fortrabbit
HTTP to HTTPSEvery request on http:// gets a 301 redirect to https://, no rule needed
CompressionOff until .htaccess enables it, see GZIP and Brotli
.ht* and .user.ini filesNever served
Visitor IPREMOTE_ADDR holds the visitor's address, not the load balancer's
Error pagesfortrabbit error pages for 4xx and 5xx, replaceable with ErrorDocument
Access syntaxApache 2.4 Require and the older 2.2 Order, Allow, Deny both work

Allowed directives

The Apache setting AllowOverride decides which directives a .htaccess file may use. On fortrabbit:

GroupExamplesAllowed
FileInfoRewriteRule, Header, ErrorDocument, AddOutputFilterByType, SetEnvIfYes
LimitOrder, Allow, DenyYes
IndexesDirectoryIndex, IndexOptionsYes
OptionsMultiViews, Indexes, SymLinksIfOwnerMatch onlyPartly
AuthConfigAuthType, AuthUserFile, RequireOnly while the dashboard password protection is off

A directive outside these groups, or one that only works in the server configuration such as <Location>, ends in a 500 Internal Server Error for every request below that folder. The Apache error shows up in the logs.

Framework and CMS defaults

Most frameworks and CMS ship a .htaccess that routes requests to index.php. Extend it instead of replacing it:

Written by humans and AI in collaboration.

AI use & editorial processEdit on GitHub ↗