Beginner Fundamentals

The .htaccess File

A .htaccess file is a configuration file placed inside a website folder. It lets you change Apache settings for that folder without editing the main configuration.

When to Use It

.htaccess is handy when you cannot edit the main config, for example on shared hosting. For servers you control, putting rules in the main config is faster and cleaner.

Enabling .htaccess

Apache only reads .htaccess if AllowOverride permits it:

<Directory /var/www/html>
    AllowOverride All
</Directory>

With AllowOverride None, the file is ignored completely.

Example .htaccess

Create the file directly in the web folder:

# Disable the directory listing
Options -Indexes

# Set a custom 404 page
ErrorDocument 404 /not-found.html

Why It Can Be Slow

Apache checks for .htaccess in every parent folder on each request. This adds overhead, so on busy sites prefer the main configuration.

Apply Changes

Changes to .htaccess take effect immediately; no reload is needed. Just test the rules in the browser. If something breaks, check the error log for the failing line.