Explainers · Explainer
What Is .htaccess in WordPress? A Plain Explanation

Short answer
The .htaccess file is a small Apache config file that tells the server how to handle requests for your WordPress site, most notably by making pretty permalinks work. It sits in the WordPress root folder next to wp-config.php, and it is hidden until you switch on hidden files. WordPress writes a short block of rewrite rules between BEGIN WordPress and END WordPress markers, and a single wrong line in the file can break every page.
Key takeaways
- The .htaccess file is an Apache config file that changes server settings for one folder without touching the main server config.
- WordPress uses the file mainly for pretty permalinks, writing rewrite rules between BEGIN WordPress and END WordPress markers.
- The file is read on every request and applies to its folder and all folders below it, so one wrong line can break every page.
- If AllowOverride is set to None, Apache ignores the file completely, so rules in it will do nothing.
- Put your own rules above the WordPress markers, back the file up first, and restore it by saving your permalink settings.
What is .htaccess in WordPress?
The .htaccess file is a small Apache config file that tells the server how to handle requests for your WordPress site.
Apache calls it a distributed config file, which means it changes settings for one folder without touching the main server config. Apache states that .htaccess files provide a way to make config changes on a per-directory basis, without modifying the main server config files directly (checked November 2026).
WordPress uses this file to control how Apache serves files from the site root folder. WordPress.org states that WordPress uses this file to manipulate how Apache serves files from its root folder, and most notably to handle pretty permalinks (checked November 2026).
The name starts with a dot, so the file is hidden on most systems. You will not see it in a file manager or an FTP client until you switch on the option to show hidden files.
The file holds plain text rules, one directive per line. Apache reads those rules on every request, so a single wrong line can change how every page on the site behaves.
How does .htaccess work?
Apache reads the file on every request and applies its rules to that folder and every folder below it.
Apache states that a file with one or more config directives is placed in a folder, and the directives apply to that folder and all subfolders below it (checked November 2026).
The file is loaded every time a page is requested, which is why Apache prefers the main server config when you have access to it. Apache states that the file is loaded every time a document is requested, and that the main config is loaded once at server start instead (checked November 2026).
When AllowOverride is None, Apache ignores the file completely. Apache states that .htaccess files are completely ignored unless you explicitly enable them for a folder (checked November 2026).
Where is the .htaccess file on your site?
The file sits in the WordPress root folder, next to wp-config.php, wp-content, wp-admin, and wp-includes.
On many shared hosts the root folder is called public_html, www, or public. Open that folder in your host file manager or FTP client, then switch on the option to show hidden files.
If the file is still missing, do not assume the site is broken. The file may not exist yet because WordPress has not written it, or your server may not use it at all.
WordPress writes the file on servers that run Apache, which is the server the WordPress documentation page is written for. On a server that runs Nginx, there is no .htaccess file, because Nginx reads its own config instead.
The Redirection plugin page shows this split in plain terms. WordPress.org states that redirects can be saved to a .htaccess file and handled by Apache itself, and that Nginx users can export redirects to a Nginx rewrite rules file instead (checked November 2026).
What does the default WordPress .htaccess file contain?
The default file holds a short block of rewrite rules between # BEGIN WordPress and # END WordPress markers.
WordPress.org gives the basic WordPress block as follows, and states that this page may be used to restore a corrupted .htaccess file (checked November 2026).
# 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
RewriteEngine On switches on the rewrite module for this folder. RewriteBase / sets the path prefix Apache uses for rewritten URLs, so a site in a subfolder would show that folder path here instead.
The two RewriteCond lines check whether the requested address matches a real file or a real folder. When neither matches, the last rule sends the request to index.php, which is how a pretty permalink such as /about/ loads the right page without index.php in the address.
WordPress rewrites everything between the two markers when it updates your permalink settings. Put your own rules above # BEGIN WordPress, never between the markers, or WordPress will replace them.
What happens when .htaccess is missing or broken?
When the file is missing or broken, posts and pages often return a 404 error while the home page still loads.
The home page loads because it does not need the rewrite rules, but every other permalink does. If the rules are gone, Apache has no way to send /about/ to index.php, so it reports that the file does not exist.
A single typo can cause a 500 error on every page instead. Apache reads the file before WordPress finishes loading, so a bad directive stops the whole site, including the dashboard.
A guide on how to fix the 500 internal server error covers the steps to take when a bad rule locks you out of the site.
A guide on how to fix the 404 error on posts covers the permalink side of the same fault, since a missing rewrite block is a common cause.
How do you restore the default .htaccess file?
Open Settings, then Permalinks, in the dashboard and click Save Changes, which makes WordPress rewrite the file for you.
That save is the first step because WordPress writes the block between the markers itself. WordPress.org states that this page may be used to restore a corrupted .htaccess file, and gives the exact block WordPress writes (checked November 2026).
Follow these steps in order:
- Back up the current file by downloading a copy to your computer.
- Open the dashboard and go to Settings, then Permalinks.
- Leave the permalink structure unchanged.
- Click Save Changes.
- Open the home page and two posts to check they load.
If the dashboard will not load, rename the file instead. Use your host file manager or FTP to rename .htaccess to .htaccess_old, then reload the site to confirm the file was the cause.
A guide on how to set up permalinks in WordPress explains the permalink settings that WordPress writes into this file.
You can also flush the rewrite rules from the terminal with wp rewrite flush. Developer.WordPress.org describes wp rewrite as the command that lists or flushes rewrite rules and updates the permalink structure (checked November 2026).
What can you add to .htaccess?
You can add rules for redirects, access control, compression, custom headers, and password protection, all above the WordPress markers.
The WordPress documentation page lists examples for each of these uses. WordPress.org shows rules for compression, custom headers, basic auth, IP limits, and file protection on the same page as the default block (checked November 2026).
Common additions include:
Options -Indexesto stop Apache listing folder contents when no index file exists.Redirect 301 /old-page/ https://example.com/new-page/to send one old address to a new one for good.- A compression block with
AddOutputFilterByType DEFLATEfor text, HTML, CSS, and JavaScript files. - A
Header setline to send an extra HTTP header with every response. - An
AuthType Basicblock with anAuthUserFilepath to password-protect a folder.
| Directive | What it does | Example use |
|---|---|---|
Options -Indexes | Stops Apache listing folder contents | Folders with no index file |
Redirect 301 | Sends one old address to a new one for good | A page that moved |
AddOutputFilterByType DEFLATE | Compresses text, HTML, CSS, and JavaScript | Faster page loads |
Header set | Sends an extra HTTP header with each response | Security headers |
FilesMatch with Require all denied | Blocks direct web access to key files | Protecting wp-config.php |
Require ip | Allows only the listed IP addresses | Locking down wp-admin |
A guide on how to set up 301 redirects in WordPress covers the redirect options in full, including plugin methods that avoid editing this file at all.
How do you edit .htaccess safely?
Back up the file first, change one rule at a time, and keep a way to reach the file when the dashboard is down.
Download a copy before you open the file for editing. A backup on your own computer is the fastest way back when a new rule breaks the site, and it costs less than a minute to make.
Edit the file with a plain text editor, not a word processor. Word processors can add hidden formatting that Apache cannot read, while a plain text editor saves exactly what you typed.
Add your rules above the # BEGIN WordPress marker. WordPress replaces everything between its markers when it updates the permalink settings, so any rule placed inside that block will vanish on the next save.
Test one change at a time. Save the file, reload the home page and one post, and check the page you meant to change before you add the next rule.
A guide on how to fix permalinks not working walks through the same restore steps when the rewrite rules are the fault.
Does .htaccess work on every host?
No, the file only works on Apache and on servers that read Apache-style config, such as LiteSpeed.
Apache is the server the file was built for, and the WordPress documentation page is titled for Apache. WordPress.org presents the file as the way Apache handles config changes on a per-directory basis (checked November 2026).
Nginx does not read the file. If your host runs Nginx, redirect and rewrite rules live in the Nginx config or in your host panel, and a .htaccess file sitting in the folder will simply be ignored.
Some managed hosts also ignore the file by choice, even on Apache. Apache states that the file should only be used when content providers need to change server settings but do not have root access, which is common on managed and control-panel hosting (checked November 2026).
What myths about .htaccess should you ignore?
The first myth is that every WordPress site has a .htaccess file, since a site on Nginx has none.
The second myth is that the file controls WordPress itself. It controls the web server, not WordPress, so it cannot change a theme setting, a plugin option, or a post. It can only change how the server handles requests before WordPress loads.
The fourth myth is that a rule inside the WordPress markers is safe. WordPress replaces everything between # BEGIN WordPress and # END WordPress when it updates the permalink settings, so custom rules there will vanish without warning.
The fifth myth is that deleting the file deletes the site. Deleting it only removes the server rules, and WordPress can write a fresh default block when you save the permalink settings again.
How do you check whether .htaccess is working?
Add a test rule, reload a page, and watch what changes, or put a nonsense word in the file and see whether the server complains.
Apache gives a simple test for a file that seems to do nothing. Apache states that you can put a nonsense word in your .htaccess file and reload the page, and that if no server error appears, you almost certainly have AllowOverride None in effect (checked November 2026).
If the nonsense word causes a 500 error, the file is being read, so remove the word at once and continue with your real rules. That error is proof the file is live, not a fault to fix.
Check the server error log when a rule fails. Apache states that the error log will likely tell you that the directive used is not permitted, or that you had a syntax error in how you wrote it (checked November 2026).
A guide on how to add security headers to WordPress shows header rules you can check in the same way, by reading the response headers your server sends.
Frequently asked questions
Where is the .htaccess file in WordPress?
Open the WordPress root folder in your host file manager or FTP client and switch on the option to show hidden files. If it is still missing, the file may not exist yet, or your server may run Nginx, which does not use .htaccess at all.
How do I restore the default WordPress .htaccess file?
Yes. Open Settings, then Permalinks, in the dashboard and click Save Changes, which makes WordPress rewrite the file. If the dashboard will not load, rename the file to .htaccess_old and restore the default block from the WordPress documentation page.
Does .htaccess work on Nginx hosting?
No. Nginx does not read .htaccess, so redirect and rewrite rules live in the Nginx config or your host panel instead. A .htaccess file sitting in the folder on a Nginx server will simply be ignored.
Can a bad .htaccess rule break my whole site?
Yes, one wrong line can cause a 500 error on every page, including the dashboard, because Apache reads the file before WordPress finishes loading. Always download a copy first and change one rule at a time.
Where should I put my own rules in .htaccess?
Put your own rules above the # BEGIN WordPress marker, never between the markers. WordPress replaces everything between BEGIN WordPress and END WordPress when it updates the permalink settings.
How do I check whether .htaccess is being read?
Put a nonsense word in the file and reload a page. If no server error appears, the file is probably ignored because AllowOverride is set to None. If a 500 error appears, the file is being read, so remove the word at once.
Sources
- Apache HTTPD / .htaccess WordPress.org
- Apache Tutorial: .htaccess files Apache HTTP Server
- Redirection plugin WordPress.org
- Redirects and Google Search Google Search Central
Is your product missing, or something out of date?
Tell us what to add or correct. We read every note and reply when we need a source. A message does not buy a ranking.
Thanks — we review requests within 3 business days.
Related guides
About the editors
Researched from the primary sources listed above and checked against our editorial rules before publishing.


