---
title: "htaccess file (.htaccess)"
description: "The .htaccess file: how Apache reads it, AllowOverride, the WordPress rules, useful protections and why it has no effect on Nginx."
language: "en"
locale: "en-US"
type: "definition"
canonical: "https://www.wp-feint.com/glossary/htaccess/"
published: "2026-10-28T08:00:00+00:00"
modified: "2026-11-22T12:07:36+00:00"
translations:
  en-US: "https://www.wp-feint.com/glossary/htaccess/index.md"
  fr-FR: "https://www.wp-feint.com/fr/definitions/htaccess/index.md"
  es-ES: "https://www.wp-feint.com/es/glosario/archivo-htaccess/index.md"
  de-DE: "https://www.wp-feint.com/de/glossar/htaccess/index.md"
  it-IT: "https://www.wp-feint.com/it/glossario/file-htaccess/index.md"
  pt-BR: "https://www.wp-feint.com/pt/glossario/arquivo-htaccess/index.md"
  nl-NL: "https://www.wp-feint.com/nl/woordenlijst/htaccess-bestand/index.md"
---

The name starts with a dot, which hides it by default in many FTP clients and file managers. The .htaccess file belongs to the [Apache](https://www.wp-feint.com/glossary/apache-http-server/) world: [LiteSpeed](https://www.wp-feint.com/glossary/litespeed/) reads it too, but Nginx, Caddy and IIS ignore it. It's the basic tool of shared hosting, where you have no access to the server configuration.

## How Apache reads .htaccess

The Apache documentation presents it as a way to change the configuration on a per-directory basis for users who don't have root access. Everything depends on the `AllowOverride` directive in the main configuration: its default value is `None`, in which case .htaccess files are completely ignored. Hosts enable it to allow permalinks, redirects and access restrictions.

![Diagram of how Apache reads .htaccess files for a request to /wp-content/uploads/photo.jpg. Apache first applies the main configuration, where AllowOverride allows .htaccess files or not. It then reads the .htaccess at the site root, with the WordPress rules, then the one in wp-content, then the one in uploads, for example to block PHP execution. The rules add up, those of the deepest directory winning in case of conflict, and these files are read again on every request.](https://www.wp-feint.com/media/2026/10/htaccess-par-dossier-en.webp)

When they're allowed, Apache looks for an .htaccess in every directory along the requested path and rereads these files on every request. A change therefore takes effect immediately, without a restart, but at the cost of extra file reads. Hence the documentation's advice: if you have access to the main configuration, put your rules there rather than in .htaccess files.

## The WordPress block

WordPress writes the rewrite rules that make permalinks work into the root .htaccess:

```
# BEGIN WordPress
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
```

Anything between the `# BEGIN WordPress` and `# END WordPress` markers can be rewritten by WordPress, for example when you save the permalink settings. Put your own rules outside these markers, and the same goes for plugins, which add their own blocks.

## Useful protections

- Block direct access to wp-config.php and to forgotten sensitive files, such as .sql backups, the .git folder or debug.log, which we cover in our article on [exposed sensitive files](https://www.wp-feint.com/exposed-sensitive-files-env-git-sql/).
- Prevent PHP execution in `wp-content/uploads` with an .htaccess dedicated to that folder.
- Restrict `wp-admin` by IP address or with an HTTP password, as in our guide to protecting wp-admin at the server level.
- Limit [hotlinking](https://www.wp-feint.com/glossary/hotlinking/) of your images based on the Referer header.

A syntax error immediately triggers a 500 error for the whole directory: keep a copy of the file before every change.

*Video: “Using .htaccess files: common usage and an example” (Dave Hollingworth)*

## For WordPress

On an Nginx server, an .htaccess file has no effect at all: its rules have to be translated into the [nginx.conf](https://www.wp-feint.com/glossary/nginx-conf/) file, which often requires help from the host. Yet many cache and security plugins assume .htaccess is there. WP Feint relies on it only for the file aliases of the Pro version, for which it generates rules for each server, and to hide its own folder: the [compatible servers and caches](https://www.wp-feint.com/features/hosting-and-cache-compatibility/) page explains where to put these rules, including on o2switch, where they must come before the LiteSpeed Cache block.

## Related terms

- [Apache HTTP Server](https://www.wp-feint.com/glossary/apache-http-server/)
- [nginx.conf](https://www.wp-feint.com/glossary/nginx-conf/)
- [LiteSpeed Web Server](https://www.wp-feint.com/glossary/litespeed/)
- [Nginx](https://www.wp-feint.com/glossary/nginx/)
- [Hotlinking](https://www.wp-feint.com/glossary/hotlinking/)


## Sources

- [Apache HTTP Server : .htaccess files](https://httpd.apache.org/docs/2.4/howto/htaccess.html)
- [WordPress Advanced Administration : Apache HTTPD / .htaccess](https://developer.wordpress.org/advanced-administration/server/web-server/httpd/)
- [Apache HTTP Server : When not to use mod_rewrite](https://httpd.apache.org/docs/2.4/rewrite/avoid.html)
