Free resource
Default WordPress .htaccess: The Original File, Multisite and Safe Restore
The default WordPress htaccess file is a handful of rewrite lines that send every "pretty" URL to WordPress's index.php. If yours got mangled by a plugin, a bad edit or a migration, the clean version is below, copied from what WordPress itself writes, not from a 2012 forum post. You also get the two multisite versions, the reason your file keeps getting rewritten, and three step-by-step ways to put the default back.
If you'd rather not touch server files at all, that's fair. Tell me about your site in the WordPress maintenance questionnaire and I reply with a plan and a fixed quote within one business day.
What .htaccess does on a WordPress site
.htaccess (a small settings file that Apache web servers read on every request) sits in the same folder as wp-config.php. WordPress uses it for one job: when someone asks for /about-us/, there is no real folder by that name, so the file tells the server to hand the request to WordPress instead of showing a "404 Not Found" error.
This applies to Apache and LiteSpeed hosting, which covers most cPanel and Plesk shared hosts. On an Nginx-only host, WordPress doesn't use .htaccess at all, and editing it changes nothing.
The default WordPress htaccess file (single site)
This is the block WordPress writes when you save your permalinks on a normal single-site install in the web root. The rules match the WordPress developer docs and WordPress's rewrite class. The three comment lines come from WordPress's file-writing function, which has added them since version 5.3.
# What it does: sends any request for a file or folder that doesn't exist to WordPress.
# What it can break: nothing on a standard install. Change RewriteBase if WordPress lives in a subfolder.
# 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 WordPressHere's what each line does, in plain English:
| Line | What it means |
|---|---|
RewriteEngine On |
Turns on Apache's URL rewriting module |
RewriteRule .* - [E=HTTP_AUTHORIZATION...] |
Passes login headers through, so app passwords and the REST API work |
RewriteBase / |
The folder WordPress lives in (here, the top level) |
RewriteRule ^index\.php$ - [L] |
If the request is already index.php, stop here |
RewriteCond ... !-f and !-d |
Only continue if no real file or folder matches the request |
RewriteRule . /index.php [L] |
Hand everything else to WordPress |
The [L] flag means "last rule, stop processing." Apache's mod_rewrite reference explains every flag.
If WordPress lives in a subfolder
If your site's address is example.com/blog/, WordPress swaps the folder into two lines and leaves the rest alone.
# What it does: the same default, for WordPress installed in /blog/.
# What it can break: every page 404s if the folder name doesn't match your real one.
RewriteBase /blog/
RewriteRule . /blog/index.php [L]Multisite versions: subfolder and subdomain
Multisite (one WordPress install running several sites) needs extra rules, and WordPress won't write them for you: the Permalinks screen skips the .htaccess save on a network, so you paste these by hand. Both blocks come from the WordPress developer docs for networks created on version 3.5 or later.
Subfolder network (example.com/site2/)
# What it does: routes each subsite's folder prefix to the shared WordPress files.
# What it can break: subsites 404 if the network is actually set up for subdomains.
# BEGIN WordPress Multisite
# Using subfolder network type: https://wordpress.org/documentation/article/htaccess/#multisite
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
# END WordPress MultisiteSubdomain network (site2.example.com)
# What it does: the same routing without the folder prefix, for subdomain networks.
# What it can break: subsites in folders stop loading if you use this on a subfolder network.
# BEGIN WordPress Multisite
# Using subdomain network type: https://wordpress.org/documentation/article/htaccess/#multisite
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
# END WordPress MultisiteOne catch: networks created before WordPress 3.5 whose image addresses contain /files/ (instead of /wp-content/uploads/) need the older block with an ms-files.php line, on the same developer docs page. Open any subsite image to check.
Why your .htaccess keeps getting overwritten
WordPress and many plugins edit .htaccess with a function called insert_with_markers. It replaces everything between # BEGIN Name and # END Name with a fresh copy and leaves anything outside those markers alone. That explains most complaints:
- You edited inside the WordPress block. WordPress regenerates it whenever rewrite rules are flushed, for example when you save permalinks. Your edit vanishes, exactly as the comment lines warn.
- A plugin owns its own block. LiteSpeed Cache writes
# BEGIN LSCACHEand# BEGIN NON_LSCACHEblocks, and Wordfence writes a# Wordfence WAFblock. Save that plugin's settings and its block is rebuilt. - A deactivated plugin left its block behind. Deactivating doesn't always clean up, and leftover lines can keep running.
The fix: put your own rules (redirects, security headers, caching) above # BEGIN WordPress, outside every marker pair. My htaccess 301 redirect cheat sheet and the force HTTPS and www rule explain why order matters: redirects need to run before WordPress grabs the request.
If lines you never wrote keep coming back, especially redirects to strange domains, that can be malware rewriting the file. Restoring the default won't stop it for long.
Restore it from the WordPress dashboard (easiest)
This rebuilds only the WordPress block and works when WordPress can write to the file, as on most shared hosts. It won't remove junk outside the markers; for a full reset, use cPanel or SFTP below.
Step 1: Open the Permalinks screen
- Log in to wp-admin.
- In the left menu, click Settings, then Permalinks.
You should see the "Permalink structure" options with one already selected. Don't change it.
Step 2: Click Save Changes without changing anything
Scroll down and click Save Changes. If it worked, "Permalink structure updated." appears at the top.
If you instead see "You should update your .htaccess file now," with a box below starting "Error: Your .htaccess file is not writable," WordPress couldn't write the file. Copy the rules from the box and use the cPanel or SFTP method. The causes are covered further down.
Step 3: Test two pages
Open your site in a private browser window and click a blog post and an inner page. Both should load. If they 404, the file isn't being read: check it's named exactly .htaccess, with the dot and no .txt on the end.
Restore it in cPanel File Manager
Step 1: Show hidden files
- In cPanel, click File Manager.
- Click Settings in the top right corner.
- Tick Show Hidden Files (dotfiles) and click Save.
You should now see files starting with a dot (cPanel's guide shows the same setting). Still nothing? Make sure you're in the folder that holds wp-config.php.
Step 2: Download a backup
Open your site's folder (usually public_html), right-click .htaccess and choose Download. Keep this copy: if anything breaks, it goes back in under a minute. A single curly quote can take a whole site down, as my guide to a 500 error after editing .htaccess shows. No .htaccess at all? Click + File, name it .htaccess, and carry on.
Step 3: Open the file in the editor
Right-click .htaccess and choose Edit. If a character encoding dialog appears, click Edit again. You should see the file's current text.
Step 4: Paste the default and save
- Select everything in the editor and delete it.
- Paste the single-site block (or your multisite block) from above.
- Click Save Changes in the top right.
Step 5: Test the site
Load your homepage and two inner pages in a private window. They should load normally. If you get a 500 error, paste your backup back in and check the error log, which names the line that broke.
Step 6: Save permalinks once
In wp-admin, go to Settings > Permalinks and click Save Changes. This confirms WordPress and the file agree.
Restore it over SFTP
Step 1: Connect with your SFTP client
Connect with a client such as FileZilla using the SFTP login your host gave you. You should see your site's folders on the right. If the login fails, check the port (usually 22 for SFTP) with your host.
Step 2: Show hidden files
In FileZilla, open the Server menu and choose Force showing hidden files. .htaccess should appear next to wp-config.php.
Step 3: Download the current file
Drag .htaccess to your computer and rename the local copy htaccess-backup.txt so you don't mix them up.
Step 4: Create the clean file
Open a plain text editor (Notepad, TextEdit in plain-text mode, VS Code), never a word processor, which swaps in curly quotes. Paste the default block and save it as .htaccess.
Step 5: Upload and overwrite
Drag the new file into the WordPress folder and choose Overwrite when asked. Then test and save permalinks as in Steps 5 and 6 of the cPanel method.
Fixing "your .htaccess file is not writable"
WordPress shows this when PHP can't write to the file. In order of likelihood:
- Wrong permissions. The WordPress file permissions guide says 644 is normally required and recommended for .htaccess. In cPanel, right-click the file, choose Change Permissions, and set 644.
- Wrong owner. After a migration or a root-level copy, the file can belong to a different user than the one PHP runs as. Permissions look fine, but writing fails. Your host can fix ownership.
- A security plugin locked it. Some set the file to 444 (read-only) on purpose. Paste the rules by hand and leave the lock on.
- An immutable flag on a VPS. With SSH access, run
lsattr .htaccess. Aniin the output means the file is locked at the system level, and only root can remove it withchattr -i .htaccess.
Never set .htaccess to 666 or 777 to make the message go away. Anyone else on the server could then rewrite your site's routing.
When to hand it off
The default file gets your URLs working; it doesn't protect anything. Once it's clean, add your own rules above the WordPress block: the Apache 2.4 security template for WordPress covers hardening, and the browser caching rules cover speed.
If the site still 404s after a clean restore, or strange redirects keep coming back, the problem is somewhere else: usually server config, a caching layer, or an infection. I've cleaned and migrated WordPress sites on cPanel, Plesk and Cloudflare setups, and .htaccess is often the first place I look.
Send me a few details in the WordPress maintenance questionnaire. BigRed's WordPress maintenance starts at $250 a month and covers updates with backups and rollback, security monitoring, uptime checks and small fixes like this one. No pressure either way.
Want a second pair of eyes on your site?
Tell me what's going on in the wordpress maintenance questionnaire. I reply with a plan and a fixed quote within one business day.