Learn how the default WordPress .htaccess file works and its importance in managing your website's functionality, security, and performance.
If your permalinks suddenly break, or a redirect plugin sends visitors somewhere weird, there’s a good chance the trail leads back to one small file: .htaccess. It sits in your WordPress root, and Apache reads it on almost every request. Learn to read it and a whole class of “why is my site doing that” problems stops being a mystery.
Here’s the block WordPress writes for pretty permalinks:
<?php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>In a real install, WordPress wraps that block between two comment lines, # BEGIN WordPress and # END WordPress. Those markers matter: WordPress owns everything between them and will rewrite it when you save permalinks or on update. So if you add your own rules, put them outside those markers, or WordPress may wipe them.
Now the block itself, line by line.
<IfModule mod_rewrite.c>: a guard. Everything inside only runs if Apache’s mod_rewrite module is loaded. No module, no crash: the server just skips the rules.
RewriteEngine On: turns the rewrite engine on. Nothing below fires without it.
RewriteBase /: sets the base path for the rules that follow. Here it’s the site root.
RewriteRule ^index\.php$ - [L]: leaves direct requests for index.php alone. The - means “don’t rewrite this,” and [L] stops rule processing right there.
RewriteCond %{REQUEST_FILENAME} !-f and RewriteCond %{REQUEST_FILENAME} !-d: two conditions. The !-f means the request isn’t a real file, and !-d means it isn’t a real directory. Both have to be true for the next rule to run.
RewriteRule . /index.php [L]: the payoff. Anything that isn’t an existing file or folder gets handed to index.php, which is how WordPress turns /about-us/ into the right page. [L] ends processing.
That’s the whole trick: real files and folders load directly, and everything else routes through WordPress so your permalink structure works.
One honest caveat. This is an Apache thing. If your host runs Nginx, there is no .htaccess file at all, and the same routing lives in the server config instead. Check what your host runs before you go hunting for a file that was never there.
Why it’s worth knowing
You don’t need to memorize Apache syntax to run a WordPress site. But knowing what this block does, and that WordPress manages it, means the next time permalinks break or a rule vanishes after an update, you’ll know exactly where to look. For the canonical version, the WordPress developer docs on .htaccess are the source of truth.


