Ffile2fix
Sign in Get started

What is a .htaccess file?

A .htaccess file is a per-directory configuration file for the Apache web server (and LiteSpeed). Site owners use it for redirects, pretty permalinks in WordPress, HTTPS enforcement, password protection and caching headers without editing the main server config.

Key facts

  • Plain text containing Apache directives such as RewriteRule, Redirect, Header and AuthType; it applies to its directory and all subdirectories.
  • Read on every request, so changes take effect immediately without a restart, but this costs some performance.
  • Only works when the main config sets AllowOverride for that directory; Nginx ignores .htaccess files completely.
  • Rewrite rules need mod_rewrite enabled and RewriteEngine On; header rules need mod_headers.
  • Created by developers, hosting control panels and CMSs such as WordPress, which writes its permalink block between # BEGIN WordPress and # END WordPress.

How to open a .htaccess file

Windows

Download it via FTP/SFTP or your host's file manager and edit it in Notepad++ or VS Code. Enable 'show hidden files' in FileZilla (Server > Force showing hidden files) if you cannot see it.

macOS

Press Cmd+Shift+. in Finder to show hidden files, then edit it in a code editor or with nano .htaccess in Terminal.

Linux

Edit it on the server with nano /var/www/html/.htaccess (adjust the path) and watch /var/log/apache2/error.log for errors after saving.

Common problems and fixes

500 Internal Server Error right after editing
A typo or an unsupported directive breaks the whole directory. Restore the previous version, then check the Apache error log, which names the bad line (for example 'Invalid command').
Redirect loop / ERR_TOO_MANY_REDIRECTS
An HTTP-to-HTTPS or www rule keeps matching its own target, often behind a proxy or CDN that terminates SSL. Add a condition such as RewriteCond %{HTTPS} off, or check X-Forwarded-Proto when behind a proxy.
Rules are ignored completely
AllowOverride is None, mod_rewrite is not enabled, or the server is actually Nginx. Ask your host or enable AllowOverride All and a2enmod rewrite on your own server.
WordPress permalinks return 404
The WordPress rewrite block is missing or the file is not writable. Re-save Settings > Permalinks or restore the standard # BEGIN WordPress block.

Often converted to or from: Nginx config, Apache VirtualHost config, web.config (IIS)

Frequently asked questions

Why can't I see my .htaccess file?

Files starting with a dot are hidden by default. Enable hidden files in your FTP client or hosting file manager; if it still is not there, create a new plain-text file named exactly .htaccess.

Do I need to restart Apache after changing .htaccess?

No. Apache reads .htaccess on each request, so changes apply immediately; clear your browser cache when testing 301 redirects because browsers cache them.

Does .htaccess work on Nginx?

No. Nginx does not read .htaccess files, so the rules have to be rewritten as Nginx server or location directives in its configuration.

See all file types β†’ Β· Browse error fixes β†’