An .htaccess file is a per-directory configuration file that controls redirects, rewrite rules and access.
An .htaccess file is a small text file that changes how the web server handles requests for a folder and everything inside it. The name starts with a dot, which hides it on most systems. You'll usually find one in your public_html folder, and WordPress creates its own there to power pretty permalinks.
For example, these two lines send every visitor from the old address to the new one:
RewriteEngine On
RewriteRule ^old-page$ /new-page [R=301,L]
What you can do with .htaccess
- Redirects: send old URLs to new ones, force HTTPS or choose between
wwwand non-www. - Rewrite rules: turn
index.php?p=12into a clean URL like/about. - Access control: block IP addresses, password-protect a folder or deny access to sensitive files.
- Caching and compression: set browser cache times and turn on GZIP.
- Custom error pages: show your own 404 page.
- Hotlink protection: stop other sites embedding your images.
How .htaccess works
The file was created for the Apache web server, and LiteSpeed reads it too. On each request, the server looks for .htaccess files in the requested folder and every folder above it, then applies their rules in order. Changes take effect straight away, with no restart.
Because rules apply to subfolders as well, a single file in public_html affects your whole site. A file in a subfolder can add or override rules just for that folder.
Nginx doesn't support .htaccess. Its settings live in the main server configuration instead, which is why rules sometimes stop working after a move to an Nginx host.
Common .htaccess problems
- 500 Internal Server Error: a single typo can break the whole site. Check your error log for the exact line.
- Redirect loops: two rules sending visitors back and forth, often when forcing HTTPS behind a CDN.
- Rules in the wrong order: rewrites are processed top to bottom, so a broad rule can catch requests before a specific one does.
- Plugins overwriting the file: some WordPress plugins rewrite sections of it, removing manual changes. Put your own rules outside their marked blocks.
How to edit .htaccess safely
- Download a copy before you change anything.
- Edit with the cPanel File Manager or over SFTP. Turn on "show hidden files" to see it.
- Make one change at a time and test your site after each.
- If something breaks, restore the copy.