WordPress .htaccess: Default Rules, Safe Edits and What 125 Sites Actually Do
The exact default WordPress .htaccess rules from core, plus crawl data from 125 live sites on what the file still controls and what moved to nginx.
Our content is written and reviewed by the Four Cents team. We may recommend our own services. Read our editorial standards.
On this page
The WordPress .htaccess file exists to do one job: route every request that is not a real file to index.php, which is what makes pretty permalinks work. Everything else people put in it is optional, and on most modern WordPress sites much of it no longer runs at all. This page gives the exact default rules from WordPress 7.1.5 core, explains each line, and uses our own crawl of 125 live WordPress sites to show what the file still controls.
Most guides to the WordPress .htaccess file hand you a block of rules to paste. This one starts with a question those guides skip: does your server read the file at all? We measured 125 live WordPress sites to answer it, and the answer changes what you should spend your time on. Every rule quoted below is taken from WordPress 7.1.5's own source code, not from another article.
What the .htaccess file is
The .htaccess file is a per-directory configuration file read by the Apache web server. In WordPress it exists mainly to do one job: send every request that is not a real file or folder to index.php, which is what makes pretty permalinks work. It is a web server file, not a WordPress file, and WordPress only writes one small block of it.
Three terms, one sentence each:
- .htaccess is an Apache configuration file placed in a folder, applying to that folder and everything under it.
- mod_rewrite is the Apache module that rewrites a requested URL into a different internal path. Without it, the rules in a WordPress .htaccess do nothing.
- Pretty permalinks are URLs like
/blog/my-post/instead of/?p=123. They are not real folders on disk, which is why a rewrite rule is needed to serve them.
The leading dot makes the file hidden on Unix-like systems, which is why people cannot find it in their FTP client. That is the whole mystery.
Does your server even read it?
We requested 159 WordPress.org Showcase sites on 29 November 2026 and confirmed 125 as reachable WordPress sites. Only 16 of those 125, 12.8%, advertise Apache or LiteSpeed, the two servers that read .htaccess. Forty-four report nginx, which ignores .htaccess entirely, and another 44 sit behind Cloudflare, which hides the origin server.
| Server reported on the homepage | Sites | Share of 125 | Reads .htaccess? |
|---|---|---|---|
| Cloudflare (origin hidden) | 44 | 35.2% | Unknown from outside |
| nginx | 44 | 35.2% | No |
| Apache | 9 | 7.2% | Yes |
| LiteSpeed | 7 | 5.6% | Yes |
| No Server header at all | 5 | 4.0% | Unknown from outside |
| Named hosts and proxies (Pagely, Flywheel, Sucuri, Netlify, Vercel, BunnyCDN and others) | 16 | 12.8% | Usually no, or not where you can edit it |
Treat those numbers carefully. A Server header can be hidden, rewritten by a proxy or set to anything the operator likes, and a site behind Cloudflare may well run Apache underneath. What the data does establish is that for a large share of real WordPress sites, the file in your web root is not the thing deciding how requests are handled. A CDN, a reverse proxy or an nginx configuration you cannot edit is in front of it.
This is the practical consequence: before you paste a performance or security block into .htaccess, check whether it is doing anything. Add a rule, reload the page, and look at the response headers. If the header you expected is not there, the file is not in charge, and you have just added a line of configuration that will confuse the next person instead of protecting anybody.
One thing the file still reliably does on shared and traditional hosting, which is where a great many small business sites live: it carries the permalink rules. That is the part worth understanding properly.
The default WordPress rules, exactly
WordPress generates its .htaccess block in WP_Rewrite::mod_rewrite_rules(). On a standard single-site install at a domain root, the generated block is seven lines wrapped in an IfModule check. Most published versions of these rules leave out the HTTP_AUTHORIZATION line, which WordPress has included for years.
Here is the block as core builds it, read from the WordPress 7.1.5 source:
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
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]
</IfModule>
# END WordPress
Line by line, because every one of them earns its place:
| Line | What it does | What goes wrong without it |
|---|---|---|
<IfModule mod_rewrite.c> | Only applies the rules if Apache has mod_rewrite loaded | Without the wrapper, a server missing mod_rewrite returns a 500 error on every page |
RewriteEngine On | Turns rewriting on for this directory | Every rule below is ignored |
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] | Copies the HTTP Authorization header into an environment variable PHP can read | Application passwords and any REST API client using basic authentication stop working, with a confusing "not logged in" error |
RewriteBase / | Sets the base path for the rules, taken from your home URL | A site in a subfolder rewrites to the wrong place |
RewriteRule ^index\.php$ - [L] | Stops the file-exists checks running against index.php itself | Needless work on every request, and edge-case loops |
RewriteCond %{REQUEST_FILENAME} !-f | Only rewrite if the request is not a real file | Images, CSS and PDFs would be routed through WordPress |
RewriteCond %{REQUEST_FILENAME} !-d | Only rewrite if the request is not a real directory | Real folders stop being reachable |
RewriteRule . /index.php [L] | Everything else goes to index.php, where WordPress takes over | Every pretty permalink returns a 404 from the server |
Two details that matter in practice. First, the RewriteBase value is not always /: core takes it from your home URL, so a WordPress install at /blog/ gets RewriteBase /blog/ and the final rule points at /blog/index.php. Copying somebody else's block onto a subfolder install is a common cause of a site that loads the home page and 404s everything else.
Second, the comment lines are not decoration. Core writes them itself, through insert_with_markers(), with exactly this wording: 'The directives (lines) between "BEGIN WordPress" and "END WordPress" are dynamically generated, and should only be modified via WordPress filters. Any changes to the directives between these markers will be overwritten.' That is a promise about behaviour. Anything you add between those markers is temporary.
How WordPress writes the file
WordPress rewrites its own block when you save permalink settings, through save_mod_rewrite_rules(). It only writes if it can: the function checks whether the file is writable, or whether the directory is writable when no file exists yet, and it returns null immediately on multisite.
The logic in core, in order:
- If the install is multisite, stop and return null. WordPress does not manage .htaccess on multisite, which is why network installs give you rules to paste by hand.
- Work out the home path and look for
.htaccessthere. - If the file does not exist, check that the directory is writable and that permalinks are using mod_rewrite. If the file does exist, check that the file is writable.
- Check
got_mod_rewrite(), which is where the server capability test happens. - Write the generated rules between the markers with
insert_with_markers(), leaving everything outside the markers untouched.
Three consequences worth knowing:
- Your custom rules are safe if they sit outside the markers.
insert_with_markers()replaces only the lines between BEGIN and END. Put your own rules above the BEGIN line or below the END line. - If the file is not writable, saving permalinks silently does less than you think. WordPress shows you the rules to paste instead of writing them. Some hosts deliberately make the file read-only, which is a reasonable security posture and a confusing one if nobody told you.
- Visiting the permalinks screen and pressing Save is the official repair. That is not folklore: it is the function above, run on purpose.
There is also a filter, mod_rewrite_rules, which is the supported way to change the generated block from a plugin. If you find yourself editing between the markers repeatedly, that filter is the answer.
Where the file is, and how to see it
The file sits in the same folder as wp-config.php and wp-load.php, which is your web root on most installs. It is hidden by default because its name starts with a dot, so you have to turn on hidden files in an FTP client or use a shell command that includes them.
# list it, including hidden files, with permissions
ls -la /path/to/site/.htaccess
# read it
cat /path/to/site/.htaccess
# find every .htaccess under the site, including the ones you forgot
find /path/to/site -name .htaccess -type f
# WP-CLI: confirm the permalink structure WordPress thinks it has
wp option get permalink_structure
wp rewrite structure --help
The find command is the one that surprises people. WordPress itself writes a second .htaccess in wp-content/uploads/ on some setups, security plugins add their own in wp-content/ and wp-includes/, and a caching plugin may add more. Apache reads all of them, nearest folder last, so a rule you cannot find in the root file may be two directories down.
Permissions: 644 is the normal setting (owner can write, everyone can read). Do not use 777. If you cannot write the file at all, that may be deliberate on your host, and the fix is to ask them rather than to force it.
When permalinks break
The classic symptom is a working home page with 404s everywhere else. That is the server failing to route requests to index.php, which means the rewrite rules are missing, broken, or in a file the server is not reading.
Work through this in order. It takes five minutes and the first two steps fix most cases.
- Save permalinks. Settings, Permalinks, then Save Changes without changing anything. This runs
save_mod_rewrite_rules(). - Look at the file. If there is no block between the markers, WordPress could not write it. Check file permissions and ownership.
- Check that mod_rewrite is available. On a server you control,
apachectl -M | grep rewrite. On shared hosting, ask the host or test with a rule that sets a header. - Check
AllowOverride. If the Apache virtual host saysAllowOverride None, your .htaccess is read and ignored. You cannot fix that from the file itself; it is a server configuration change. - Check the RewriteBase. A subfolder install needs the subfolder, not
/. - Check for a second .htaccess in a parent folder on the server, which can override what you expect.
Related symptoms have their own causes and their own pages: a 403 Forbidden is usually a permission or security rule rather than a rewrite problem, a redirect loop is normally a conflict between a site URL setting and a redirect rule, and a 404 on a single page is a WordPress-level problem, not a server one. Telling them apart quickly is most of the skill.
Why searches for this are rising
Searches for "wordpress htaccess" in the United States averaged 590 a month over the last twelve months, up from 390 in November 2025 to 880 in both September and October 2026, according to Google Ads data pulled through DataForSEO on 29 November 2026. Keyword difficulty for the term is 16 out of 100, and the cost per click is zero, which tells you nobody is selling anything against it.
A rising search volume with a zero cost per click is a specific shape of demand: people with a broken site, not people with a budget. That matches what the results page looks like. The United States results for the term on 29 November 2026 carried an AI Overview citing WordPress's own developer documentation, a code gist and two hosting providers' help pages, followed by nine organic results, most of them titled around the default file's contents or how to create one. There were no "people also ask" questions at all, which is unusual and suggests Google treats the query as a lookup rather than a topic.
Our reading of why it is growing: more WordPress sites now sit behind a CDN or on nginx, so the advice that worked five years ago fails silently, and people search again. That is exactly why this page leads with whether your server reads the file.
Security rules, and what sites actually do
The .htaccess rules worth adding are the ones that block access to files that should never be public. Our crawl shows how uneven that is in practice: of 125 live WordPress sites, 41.6% answer as a live XML-RPC endpoint and 40.8% still serve readme.html, which discloses the WordPress version.
| What we requested | Result across 125 WordPress sites |
|---|---|
/.htaccess | 403 on 110 sites (88.0%), 404 on 6 (4.8%), 200 on 3 (2.4%), and 2 of those 3 returned actual rewrite directives |
/xmlrpc.php | Answering as a live endpoint on 52 (41.6%), blocked or removed on 62 (49.6%) |
/readme.html | Served on 51 (40.8%), of which 49 exposed a parseable version string; 403 on 51; 404 on 18 |
| WordPress generator meta tag | Present on 32 (25.6%); 18 of those declared a 7.1 version |
Three sites in a sample of 125 served their own .htaccess file as readable text. That is a configuration failure rather than a WordPress one, and it is worth a thirty second check on your own site: request https://yourdomain/.htaccess in a browser. A 403 or 404 is fine. Text is not. We are not naming the sites.
The rules below are the ones we actually use. Each has a reason, and none of them is a substitute for keeping software updated.
# Keep .htaccess, wp-config.php and debug logs out of the browser
<FilesMatch "^(\.htaccess|wp-config\.php|debug\.log|readme\.html|license\.txt)$">
Require all denied
</FilesMatch>
# Stop PHP executing inside the uploads folder (place in wp-content/uploads/.htaccess)
<FilesMatch "\.(php|php\d|phtml|phar)$">
Require all denied
</FilesMatch>
# Turn off directory listing
Options -Indexes
# Block XML-RPC entirely, if nothing you use needs it
<Files xmlrpc.php>
Require all denied
</Files>
Notes on each, because the internet is full of versions of these that are wrong:
Require all deniedis Apache 2.4 syntax. The olderOrder deny,allowform is Apache 2.2 and causes a 500 error on 2.4 without the compatibility module. Check your Apache version before pasting either.- The uploads rule belongs in
wp-content/uploads/.htaccess, not in the root file, and it is one of the highest-value rules on the list: a PHP file dropped into uploads is how a great many compromises get a foothold. Our guide on fixing a hacked WordPress site covers finding those files. - Blocking XML-RPC breaks the WordPress mobile app, some Jetpack features and any remote publishing tool. Check before you block. Our page on the WordPress login URL covers the related question of protecting wp-login.php, which needs more care than a blanket deny.
- Do not block
wp-cron.phpat the server level unless you have replaced it with a real cron job, or scheduled posts and plugin tasks stop running.
One more point on hardening generally: our crawl found HSTS on 53.6% of these sites, X-Content-Type-Options on 36.8%, X-Frame-Options on 34.4%, Referrer-Policy on 22.4% and a Content-Security-Policy on 21.6%. Those headers can be set in .htaccess with Header always set, and they are a better use of ten minutes than most rule blocks, because they are checkable from outside. Our free WordPress vulnerability scanner reads them, and the WordPress security checklist puts them in order of value.
Compression and caching, measured
Compression and browser caching are the two performance jobs .htaccess traditionally does, and the sites we measured mostly have them handled already. Across 125 sites, 70.4% served the homepage with Brotli compression and 28.0% with gzip; only 2 sites, 1.6%, served it uncompressed.
For static assets we fetched the first stylesheet each site loads from wp-content or wp-includes and read its caching headers. On the 118 sites where that worked:
| Measure on a real stylesheet | Result |
|---|---|
| Cache-Control max-age of one day or more | 102 of 118 (86.4%) |
| Median max-age | 31,536,000 seconds, exactly one year |
| Shortest max-age seen | 180 seconds |
| Longest max-age seen | 315,360,000 seconds, ten years |
| max-age under one day | 4 of 118 |
| no-store, no-cache or max-age=0 | 2 of 118 |
| No Cache-Control header at all | 10 of 118 |
| Compressed (Brotli) | 67 of 118 |
| Compressed (gzip) | 44 of 118 |
| Not compressed | 7 of 118 |
A one-year median is the right answer for versioned assets, and it is what WordPress makes safe by appending ?ver= to its own stylesheets and scripts. The ten sites with no Cache-Control at all are the ones leaving real speed on the table, and the fix is small:
# Compression (Apache)
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/css text/plain text/xml application/javascript application/json image/svg+xml
</IfModule>
# Browser caching for versioned static files
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/css "access plus 1 year"
ExpiresByType application/javascript "access plus 1 year"
ExpiresByType image/webp "access plus 1 year"
ExpiresByType image/avif "access plus 1 year"
ExpiresByType font/woff2 "access plus 1 year"
ExpiresByType text/html "access plus 0 seconds"
</IfModule>
Two warnings. Never set a long cache lifetime on HTML: that is the rule that makes a site show old content to returning visitors with no way to force a refresh. And if a CDN or a caching plugin is already setting these headers, adding them here produces duplicate or conflicting values, which is worse than not setting them. Check the response headers before and after. Our WordPress caching guide covers how the layers interact, and when a slow site is a hosting problem rather than a configuration one, our speed optimization service starts with a free review and a fixed price.
Redirects, and when to use something else
.htaccess is the fastest place to run a redirect, because the server answers before PHP starts. It is also the worst place to keep hundreds of them, because there is no interface, no log and no way for a non-technical colleague to add one safely.
The syntax for the two cases that cover most needs:
# One page to another, permanently
Redirect 301 /old-page/ https://example.com/new-page/
# A pattern, with a capture
RedirectMatch 301 ^/news/(.*)$ https://example.com/blog/$1
# Force HTTPS, only if nothing in front of the server does it already
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
</IfModule>
Put those above the # BEGIN WordPress line so WordPress does not overwrite them and so they run before the rewrite to index.php.
| Situation | Where the redirect belongs | Why |
|---|---|---|
| A handful of permanent moves, set once | .htaccess | Fastest, no PHP, no database |
| HTTPS and www canonicalisation | .htaccess, or the CDN if one is in front | Must happen before anything else; only do it in one place |
| Hundreds of moves from a site migration | A redirect plugin | Searchable, logged, editable by the person doing the content work |
| Rules that need to know about logged-in users or post types | PHP, in a plugin | The server has no idea what a post type is |
| Temporary campaign URLs | A plugin, with an expiry noted | Temporary rules in a config file become permanent by accident |
Our guide on setting up redirects in WordPress covers the plugin route and how to avoid chains, which are the thing that actually costs you rankings: every extra hop is another round trip, and a chain of three is common after two site redesigns.
If you are on nginx or behind a CDN
nginx does not read .htaccess, by design. The equivalent rules live in the server configuration, which only the host can change. On managed WordPress hosting the permalink rule is already in place and you do not need to do anything.
The nginx equivalent of the WordPress permalink block is one line in a location block:
location / {
try_files $uri $uri/ /index.php?$args;
}
What this means for the rest of this page, in order of how often it bites people:
- Security rules. Ask your host to deny access to the sensitive files, or use a plugin that can refuse the request in PHP. A PHP-level block is slower than a server-level one but still effective.
- Compression and caching. Almost always handled by the host or the CDN already. Measure before you ask for changes.
- Redirects. Use a plugin, or the CDN's own redirect rules if it has them. Putting the same redirect in two layers is how loops happen.
- A leftover .htaccess on an nginx host is harmless and misleading. It will sit there for years looking like configuration. If you move a site from Apache to nginx, write down which rules were load bearing before you lose them.
- LiteSpeed reads .htaccess. If your host runs LiteSpeed or OpenLiteSpeed, everything here applies, and the LiteSpeed cache plugin writes its own block into the file.
The crawl figure is the thing to remember: 35.2% of the WordPress sites we measured report nginx and another 35.2% hide behind Cloudflare. For a majority of modern WordPress sites, .htaccess is either ignored or not the outermost layer.
What breaks a site, and the two minute recovery
A syntax error in .htaccess takes the whole site down with a 500 Internal Server Error, instantly, including the admin. The recovery is to rename the file, which takes about two minutes and needs only FTP or a file manager.
The recovery, in order:
- Rename
.htaccesstohtaccess-broken.txt. The site comes back, with pretty permalinks broken. - Log in to WordPress, go to Settings, Permalinks, and press Save Changes. WordPress writes a fresh default block.
- Open the renamed file and add your custom rules back one at a time, checking the site after each.
- Keep a copy of the working file somewhere outside the web root before you next edit it.
The most common causes of that 500, from most to least frequent in our experience: Apache 2.2 syntax pasted onto Apache 2.4, a rule referring to a module the server does not have without an IfModule wrapper, an unclosed <IfModule> or <Files> tag, and a smart quote pasted from a word processor or a web page instead of a plain apostrophe. The last one is invisible on screen and is worth checking first when a rule that should work does not.
Before any edit: back the file up. Not the whole site, just the file. Copy it to your computer, edit the copy, upload it. A full-site backup covers the bigger picture, but for this specific file a local copy is enough.
What not to put in .htaccess
Three categories of rule do more harm than good: blanket blocks on things WordPress needs, user-agent blocking lists, and anything duplicating what a CDN already does.
| Popular advice | What it actually does | Do this instead |
|---|---|---|
Block all access to wp-content | Breaks every image, stylesheet and script on the site | Block PHP execution in uploads only |
Deny wp-cron.php | Stops scheduled posts, backups and plugin tasks | Disable WP-Cron in config and add a real server cron job |
| Long user-agent blocklists | Grows stale, costs a string comparison on every request, and blocks nothing determined | Control crawlers in robots.txt and abuse at the CDN |
| Restrict wp-login.php by IP address | Locks you out the day your home IP changes | Strong passwords plus two factor authentication |
| Hotlink protection by referrer | Breaks legitimate previews and some feed readers | Do it at the CDN, where it can be tested and turned off |
| Anything pasted between the WordPress markers | Gets overwritten the next time permalinks are saved | Put it outside the markers, or use the mod_rewrite_rules filter |
The broader point: .htaccess is the wrong place for anything that needs to be understood later. It has no comments by convention, no version history, no interface and no audit trail. Every rule you add is a rule the next person has to reverse engineer. Our full hardening list, in order of value, is in how to secure a WordPress website.
The .htaccess checklist
Run this once on any site you look after. It takes about fifteen minutes and finds the three problems that matter.
- Request
https://yourdomain/.htaccessin a browser. You want 403 or 404, never readable text. - Request
https://yourdomain/readme.html. If it loads, your WordPress version is public. Deny it or delete it. - Check the
Serverresponse header to see whether you are on Apache, LiteSpeed, nginx or behind a proxy, so you know whether this file does anything. - Open the file and confirm the WordPress block sits between its markers, intact, with the right
RewriteBase. - Confirm your custom rules are outside the markers.
- Run
find . -name .htaccessand read every file it finds, not just the root one. - Check there is an
.htaccessinwp-content/uploads/blocking PHP execution. - Decide about XML-RPC on purpose: blocked, or open because something you use needs it.
- Check the homepage response for
Content-Encodingand a static asset forCache-Control. If either is missing, fix the one that is missing rather than pasting a block of both. - Confirm HTTPS and www canonicalisation happen in exactly one place.
- Save a copy of the working file outside the web root.
- Write down, in the file or in your notes, why each custom rule exists.
How we compiled this
The rules and behaviour described here are read from the WordPress 7.1.5 source code, specifically WP_Rewrite::mod_rewrite_rules() in wp-includes/class-wp-rewrite.php and save_mod_rewrite_rules() and insert_with_markers() in wp-admin/includes/misc.php. The measurements come from our own crawl of WordPress.org Showcase sites on 29 November 2026. The search figures come from Google Ads data pulled through DataForSEO the same day.
- Crawl method: we took the site list published on the WordPress.org Showcase, requested each homepage once with a browser-like Accept-Encoding and an identifying user agent, and kept the 125 sites that both answered 200 and showed a WordPress signal (a generator tag, a
wp-contentorwp-includespath, or the api.w.org link relation). For each of those we then made one request each to/.htaccess,/xmlrpc.php,/readme.htmland the first stylesheet the homepage loads. Five requests per site, concurrency four, 20 second timeout. Three sites did not respond and 31 answered but showed no WordPress signal. - What the server figures can and cannot tell you: the
Serverheader is self-reported and can be removed or changed. A Cloudflare response tells you nothing about the origin. We report what the header said and label the unknowns as unknown rather than guessing. - Why the Showcase: it is a public list of real, named WordPress sites, which makes the sample reproducible. It is also biased towards larger and better-resourced sites, so treat these figures as a best case. A sample of small business sites would almost certainly show worse security headers and more exposed files.
- Ethics: every request was a plain GET to a public URL, the same request any browser makes, one per path, with a user agent identifying us and a link to our contact page. We are not naming the three sites that served a readable .htaccess.
- Search data: "wordpress htaccess", United States, 590 average monthly searches, keyword difficulty 16, cost per click $0.00, with the twelve month series running 390 in November 2025 to 880 in September and October 2026.
We will re-run the crawl in six months and update the figures. If your own numbers differ, that is expected: a sample of 125 sites has wide error bars, and the point of publishing the method is that you can repeat it.
To cite this page: "WordPress .htaccess: Default Rules, Safe Edits and What 125 Sites Actually Do, Four Cents WordPress Studio, 29 November 2026", with a link to this URL.
Frequently asked questions
Where is the .htaccess file in WordPress?
In the same folder as wp-config.php, which is the web root on most installs. The leading dot makes it hidden, so turn on hidden files in your FTP client or run ls -la. Run find /path/to/site -name .htaccess to catch the extra copies that plugins add in wp-content and uploads.
What are the default WordPress .htaccess rules?
Seven directives inside an IfModule mod_rewrite.c wrapper: RewriteEngine On, the HTTP_AUTHORIZATION environment rule, RewriteBase, a rule excluding index.php, two conditions excluding real files and folders, and a final rule sending everything else to index.php. WordPress generates them in WP_Rewrite::mod_rewrite_rules().
Why do my WordPress permalinks return 404?
Usually because the rewrite rules are missing or not being read. Go to Settings, Permalinks and press Save Changes, which makes WordPress rewrite the block. If that does not work, check file permissions, whether mod_rewrite is loaded, whether the Apache virtual host sets AllowOverride None, and whether RewriteBase matches your install path.
Can I add my own rules to the WordPress .htaccess file?
Yes, but put them outside the "# BEGIN WordPress" and "# END WordPress" markers. Core replaces only the lines between those markers when permalinks are saved, and the file says so in its own comments. To change the generated block itself, use the mod_rewrite_rules filter.
Does nginx use .htaccess?
No. nginx ignores .htaccess by design, and the equivalent rules live in the server configuration, which usually only the host can change. The nginx equivalent of the WordPress permalink rule is try_files $uri $uri/ /index.php?$args inside a location block.
How do I fix a 500 error caused by .htaccess?
Rename the file to htaccess-broken.txt, which brings the site back immediately with permalinks broken. Log in, go to Settings, Permalinks and press Save Changes so WordPress writes a fresh block, then add your custom rules back one at a time. Common causes are Apache 2.2 syntax on Apache 2.4, a missing IfModule wrapper, an unclosed tag and smart quotes pasted from a web page.
Should I block xmlrpc.php in .htaccess?
Only after checking what uses it. Blocking it breaks the WordPress mobile app, some Jetpack features and remote publishing tools. In our crawl of 125 live WordPress sites on 29 November 2026, 41.6% answered as a live XML-RPC endpoint and 49.6% had it blocked or removed, so site owners genuinely split on this.
Is .htaccess the right place for redirects?
For a handful of permanent moves and for HTTPS canonicalisation, yes, because the server answers before PHP starts. For hundreds of redirects from a migration, use a redirect plugin instead: it is searchable, logged and editable by whoever does the content work. Never run the same redirect in two layers.
What file permissions should .htaccess have?
644, meaning the owner can write and everyone can read. Never 777. Some hosts deliberately make the file read-only, in which case WordPress shows you the rules to paste instead of writing them, and the fix is to ask the host rather than to force the permissions.
Do caching and compression rules in .htaccess still help?
Only if nothing in front of the server is already doing the job. Across the 125 sites we measured, 70.4% already served the homepage with Brotli compression and 86.4% of measured stylesheets carried a Cache-Control max-age of a day or more, with a median of exactly one year. Duplicating headers that a CDN already sets causes conflicts rather than speed.
Sources
Each figure and date above comes from one of these. The retrieved date is when we last confirmed the source still says what we say it says.
- WP_Rewrite::mod_rewrite_rules() in WordPress core WordPress Developer Resources. Retrieved 2026-11-29.
- save_mod_rewrite_rules() in WordPress core WordPress Developer Resources. Retrieved 2026-11-29.
- insert_with_markers() in WordPress core WordPress Developer Resources. Retrieved 2026-11-29.
- WordPress 7.1.5 source download (rules read from wp-includes/class-wp-rewrite.php) WordPress.org. Retrieved 2026-11-29.
- Using Permalinks WordPress.org Documentation. Retrieved 2026-11-29.
- Apache HTTP Server: .htaccess files The Apache Software Foundation. Retrieved 2026-11-29.
- Apache mod_rewrite documentation The Apache Software Foundation. Retrieved 2026-11-29.
- Apache access control with Require directives The Apache Software Foundation. Retrieved 2026-11-29.
- nginx try_files directive nginx. Retrieved 2026-11-29.
- WordPress.org Showcase (site list used for the crawl) WordPress.org. Retrieved 2026-11-29.
- Search volume, trend and keyword difficulty for "wordpress htaccess", United States DataForSEO (Google Ads data). Retrieved 2026-11-29.
- Hardening WordPress WordPress Developer Resources. Retrieved 2026-11-29.
About the author
Founder, Accountant & Project Manager, Four Cents
Hamza Hai is a founder of Four Cents and its accountant and project manager. She keeps projects on track and the numbers clear.
She manages timelines, scope and client communication, so there are no surprises for clients along the way.
She writes the guides on WPDeveloper.ca, including its WordPress planning guides. They draw on the quoting and scoping work she does for Four Cents clients every week.
Areas of expertise
- Software and app project management
- Development costing and estimates
- Project scoping
- Budgeting for software projects
All articles by Hamza Hai (140 on Four Cents WordPress Studio)
Reviewed by Zee, Founder & Lead Developer, Four Cents
Zee leads every Four Cents build as the senior full-stack engineer, from the first call to launch and beyond, and technically reviews the articles on this site.
Our editorial standards: who writes and reviews our articles, where our prices come from and how to report a correction.