How to Edit .htaccess in WordPress Without Accidentally Taking Your Site Down

feature image

You’ve opened the hidden file, and now you’re stuck between scrolling, copying, and closing the window. That hesitation is wise because one wrong line here can take the whole site offline, and nobody wants to be the person who did that on a Tuesday afternoon.

Here’s the good news: editing .htaccess safely is a short, repeatable process, not a guessing game. Whether you’re fixing redirects or improving website security, the steps are the same whether you run a small blog or a busy store, and every one of them leaves you a way back.

By the end of this guide, you’ll know how to make a change without risking the whole site, and exactly what to do if something goes wrong.

TL;DR: Confirm your server runs Apache, back up the whole site, and save an untouched copy of .htaccess before you edit. Regenerate WordPress’s rules from Settings > Permalinks first, make one small change, and test the URLs it affects. For security-related rules, see our guide to setting up WordPress .htaccess security. Restore the untouched copy if you hit a 500 error.

First, check that your server uses .htaccess

.htaccess is an Apache feature, so confirm that before you go hunting for the file. If your site runs on Nginx, the file does nothing, and editing it won’t change how your site behaves. Nginx settings usually live with your host or server administrator instead.

If you’re not sure which server you’re on, ask your host. It’s a one-message question, and it saves you from editing a file that has no effect. A missing .htaccess file doesn’t prove you’re on Nginx, though. The file might be hidden, WordPress might not have generated it yet, or the folder might not be writable.

Apache also decides what it will accept in that folder. Some directives work in the main server configuration but get refused in .htaccess, so your host’s settings determine what actually runs. If a directive you copied from a guide does nothing, this is often why.

Find the file in the WordPress root

The file sits in the WordPress root, the folder that holds wp-admin, wp-content, and wp-includes side by side. On many hosts that folder is called public_html, though some use httpdocs, www, or another name. Ignore the label and look for those three folders.

WordPress root file browser showing the public_html folder with wp-admin, wp-content, and wp-includes

Because the name starts with a dot, the file stays hidden by default. Turn on an option such as “Show hidden files,” “Show dotfiles,” or “View hidden files,” whichever your FTP client or file manager uses.

If the file still won’t appear, check these common causes:

WordPress Site Health filesystem permissions diagnostic
  • WordPress hasn’t generated its rules yet, which happens on fresh installs and some custom setups
  • File permissions block the file from being created or listed
  • You’re looking in a parent folder rather than the WordPress root
  • WordPress lives in a subfolder, so its rules must match that path
  • The site runs on Nginx or another server setup, as covered above

Don’t copy a rule block from a root install into a subfolder install, or the reverse. The paths and rewrite rules differ, and a copied block can break the site in ways that are hard to trace. Let WordPress generate the rules for the install you actually have.

Let WordPress regenerate its rules first

Before you open the file at all, let WordPress rebuild its own rules, because that fixes more permalink problems than most people expect. Sign in, go to Settings > Permalinks, confirm the structure you want is selected, and click Save Changes, even if you haven’t changed anything.

WordPress Permalink Settings screen with the Save Changes button

Saving that screen flushes WordPress’s rewrite rules. If .htaccess is writable, WordPress updates the file for you. If it isn’t, WordPress displays the exact rules to paste in manually, and you should use those rules rather than a block from another site. The WordPress documentation on the Permalinks screen covers this in more detail.

This step solves most 404s that follow a permalink change. It won’t diagnose everything, though. A 404 can also come from the wrong site URL in your settings, a host-level rule, a plugin conflict, or a subfolder setup. If saving Permalinks changes nothing, look at those causes before you touch the file.

For more help identifying file-related problems, see MalCare’s guide to fixing a corrupted .htaccess file in WordPress.

Backup before you change a single line

Before any manual edit, keep two separate copies: a full site backup and an untouched download of the current .htaccess file. The full backup protects the whole site, while the file copy gives you a fast way to undo one configuration change.

Save the file outside your hosting account, give it a name with the date, and leave it alone while you experiment. If you have a staging copy, test there first. Also note what you’re changing and which URLs you’ll test afterward. Otherwise, several unrelated edits can blur into one failure you can’t untangle.

If you don’t have an off-host backup yet, set one up before you edit anything. BlogVault keeps encrypted copies away from your host and offers test restores, so a file you break by mistake can be undone without digging up an old download.

BlogVault backup details showing protected WordPress site copies

Pick an access method

Choose a route that works even if your dashboard stops responding, because that’s the moment you’ll need a way back most. You have three common options.

WordPress Theme File Editor showing its direct-edit warning
  • SFTP or FTP. Download the file, edit the copy in a plain-text editor, and upload it only after you’ve checked the change. SFTP is the better choice because it encrypts the connection. If your host only offers plain FTP, ask about secure access before you send your login details.
  • Your host’s file manager. Turn on hidden files, open the WordPress root, and download the file before using the Edit or Code Editor option. Download it first even if your panel makes automatic backups.
  • A WordPress editor plugin. Useful when you can reach your dashboard, and some offer syntax checks and timestamped backups. A syntax check catches malformed text, but it can’t confirm that a redirect behaves correctly or that your host allows the directive.

Whichever route you pick, keep the file as plain text, saved as exactly .htaccess with no extra extension. Rich-text editors sneak in formatting characters that break the file, so avoid them.

Make the edit the right way

Treat .htaccess as server configuration, not a notebook for snippets you found online. Before you add anything, pin down four things: the exact behavior you need, the Apache directives your host supports, which URLs should change, and which must stay the same.

Leave WordPress’s generated block alone. It usually looks like this:

# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

Custom rules belong outside that block, and your server has to accept them there. A later permalink save or plugin update can regenerate the managed block and wipe out anything you added inside it. Some plugins also write their own marked sections, labeled with their name between BEGIN and END lines, so leave those alone too.

Be cautious with rules copied from old tutorials. Apache 2.2 access-control examples and <Directory> blocks may not fit a modern setup. Broad IP blocks or canonical redirects from another site can send the wrong visitors somewhere else. A rule can look valid and still create a redirect loop or lock out real visitors.

Forcing HTTPS, protecting an admin path, and blocking bad traffic often work better at the host level, in a firewall, or in a dedicated security tool. Also check for host-level rules. Some hosts set redirects or access controls outside your .htaccess file, and those can override what you write. If your edit seems to do nothing, ask your host whether a rule upstream is taking precedence.

Once the file is saved, set its permissions to 644, which is usually right. Avoid 777, because it lets anyone on the server write to the file.

Test the outcome you were after

After saving, test the result you wanted, because a homepage that loads once tells you very little. For a permalink change, open the homepage, a post, a page, an archive, and the login screen. For a redirect, test the old URL, the new destination, the variants that matter (http versus https, www versus non-www), and one URL that should stay the same.

Watch for redirect loops, unexpected login failures, 404s, broken images, and problems that affect only some URLs. Use a private browser window so caching doesn’t hide the result. If you still see the old behavior, clear the relevant WordPress cache and test again. Many redirect bugs appear on a second visit or on one specific URL, so keep testing after the first pass.

What if the site breaks?

A 500 error right after an edit is your signal to roll back first and investigate second. Replace the edited file with your untouched copy through SFTP or the file manager, then reload the site. Once it’s back, compare the two files and reintroduce your change one line at a time.

WordPress Plugin File Editor with BlogVault selected

Here’s how to handle the other situations you might face:

  • A 404 on every page except the homepage. The rewrite rule is missing. Save Settings > Permalinks to regenerate it, or paste the rules WordPress displays if the file isn’t writable.
  • A redirect loop. Remove the most recent redirect, then test the same URL again. Loops usually come from two rules fighting each other, or from a rule that matches its own destination.
  • Locked out of wp-admin. You can still fix this through FTP or the file manager. Restore the untouched copy, and the dashboard usually returns on the next load.
  • The file won’t save or upload. Check the permissions. You should be able to write to the file, and the folder shouldn’t block changes.
  • The 500 persists after the rollback. The .htaccess edit may not be the only change. Check recent plugin, theme, DNS, or host updates, and ask your host for the server error log.

Error messages differ from host to host, so don’t guess the cause from a 500 response alone. Common culprits include a malformed directive, a directive your server doesn’t allow in .htaccess, an invalid rewrite condition, or a rule copied from the wrong server context.

When the file keeps changing, look beyond the file

If you restore the file and it changes again, or an unexplained redirect keeps appearing, stop treating it as a syntax problem. A file that reappears can be a visible symptom of a wider compromise. Keep your backup, restore a known-good state if the site is unsafe, and investigate the whole installation instead of deleting lines one at a time.

If the symptom is an unexpected redirect, read up on the hacked redirect pattern in WordPress, since it’s a well-documented case. A site-wide scanner can then check the rest of the installation. MalCare scans WordPress files, the database, uploads, plugins, themes, and scheduled tasks for malware, using signature matching, file-integrity checks, and behavioral analysis.

MalCare WordPress security scan summary showing malware detection results

It’s a scanning step, though, not an .htaccess editor, so keep your backup and rollback plan in place alongside it.

Quick checklist before your next edit

  1. Confirm the site runs Apache and that the directives you need are allowed.
  2. Find the WordPress root beside wp-admin, wp-content, and wp-includes.
  3. Show hidden files before deciding the file is missing.
  4. Regenerate the rules from Settings > Permalinks if that’s the real problem.
  5. Back up the full site and download an untouched copy of .htaccess.
  6. Make one narrow change outside WordPress’s managed block.
  7. Save it as plain text named exactly .htaccess, with permissions of 644.
  8. Test the exact URLs your change affects, in a private window.
  9. Restore the untouched copy after any 500 error or unexpected behavior.
  10. Investigate the whole site when changes or redirects keep coming back.

FAQs

Where is the .htaccess file in WordPress?

It sits in the WordPress root, beside wp-admin, wp-content, and wp-includes. It’s hidden by default, so turn on hidden files in your FTP client or file manager.

Can I edit .htaccess from the WordPress dashboard?

Only with a plugin. WordPress doesn’t include an editor for this file, so you’ll need FTP, your host’s file manager, or an editor plugin you trust.

What happens if I delete .htaccess?

WordPress can usually recreate it. Save Settings > Permalinks, and WordPress writes the file back if it’s writable. Restore your backup first if you need the exact custom rules you had before.

It can, if you put them inside WordPress’s managed block. Keep custom rules outside that block, and check the file after every permalink save.

Is .htaccess the same as the server configuration?

No, but it’s part of it. Some server settings can only be changed by your host, and .htaccess can only do what your host allows it to do.

Conclusion

Editing .htaccess is less about being a server expert and more about working in the right order. Confirm you’re on Apache, let WordPress regenerate its rules before you reach for the file, back up everything, and change one thing at a time.

Test the URLs you actually touched, and keep that untouched copy within reach, because it’s the fastest way out when a 500 error shows up. Do that, and the hidden file stops feeling like a trap and becomes a tool you know how to use.

Akshat is the Founder and CEO of BlogVault, MalCare, and WP Remote. These WordPress plugins, designed for complete website management, allows 100,000+ customers to build and manage high-performance websites with ease.