Developer · Guide
How to Edit the .htaccess File in WordPress Safely

Short answer
To edit the .htaccess file in WordPress, connect to your site with your host's file manager or an FTP client, open the site's root folder, show hidden files and edit .htaccess. Download a backup copy first, add your rules outside the BEGIN WordPress and END WordPress markers, save, and test the site immediately. If the site breaks, restore the backup.
Key takeaways
- The .htaccess file sits in the WordPress root folder and is hidden by default.
- It only works on Apache and LiteSpeed servers, not on Nginx.
- Always download a backup copy before editing.
- Keep custom rules outside the BEGIN WordPress and END WordPress block.
- A single typo can cause a 500 error, so test right after saving.
What is the .htaccess file?
The .htaccess file is a configuration file used by Apache and LiteSpeed web servers to control things like redirects, permalinks, caching headers and access rules for the folder it sits in.
WordPress uses it mainly to make pretty permalinks work, by sending requests for clean URLs to the index.php file.
Plugins for caching, security and redirects often add their own rules to the same file.
Our explainer on what .htaccess is in WordPress covers the background in more detail.
Does your server use .htaccess?
Only Apache and LiteSpeed servers read .htaccess files; Nginx ignores them completely and uses its own server configuration instead.
Ask your host or check your hosting dashboard if you are not sure which server you use. Many shared hosts run Apache or LiteSpeed.
If your site runs on Nginx, editing .htaccess does nothing. Rules must be added to the Nginx configuration, usually by the host.
The Apache documentation on .htaccess files explains how the server reads them and when they apply.
What if your site runs on Nginx?
On Nginx, ask your host to add the equivalent rules to the server configuration, or use the host's dashboard tools for redirects, caching and security headers.
The nginx documentation describes how its configuration works, but most site owners on managed hosting cannot edit it directly.
Many managed hosts provide redirect managers and header settings in their dashboards for exactly this reason. Check those before asking support.
Plugins that write redirects to the database, rather than to .htaccess, also work on Nginx, which makes them a portable choice.
Where is the .htaccess file?
The main .htaccess file is in the WordPress root folder, the same folder that contains wp-config.php, wp-admin and wp-includes, often called public_html or www on shared hosting.
Files that start with a dot are hidden by default. Turn on Show hidden files in your file manager or FTP client to see it.
Other folders, such as wp-content/uploads, can have their own .htaccess files, usually added by security plugins.
If no .htaccess exists, WordPress can create one when you save your permalink settings, as long as the folder is writable.
How do you back up .htaccess before editing?
Download the file to your computer, or copy it on the server with a new name such as .htaccess-backup, before you change anything.
This takes seconds and lets you undo any mistake instantly by restoring the original file.
Avoid naming the backup with a .htaccess extension in the same folder. A clear name like htaccess-backup.txt prevents the server from treating it as configuration.
Keep a dated copy each time you make a significant change, so you can trace when a rule was added.
How do you edit .htaccess with the host's file manager?
Log in to your hosting control panel, open File Manager, go to the WordPress root folder, enable hidden files, right-click .htaccess and choose Edit, make your change, then save.
- Log in to your hosting control panel
- Open File Manager
- Go to public_html or your site's root folder
- Enable Show hidden files in settings
- Right-click .htaccess and choose Edit
- Add or change your rules
- Save and test the site
The built-in editor is convenient for small changes. For larger edits, copy the content into a text editor, change it there, and paste it back.
Make sure the editor saves with plain text and Unix line endings, which most host file managers do automatically.
How do you edit .htaccess with FTP?
Connect with an FTP or SFTP client, enable hidden files, download .htaccess, edit it in a plain text editor, upload it back to the same folder and overwrite the original.
Use SFTP where your host supports it, since it encrypts the connection and your password.
Use a code editor, not a word processor. Word processors add hidden formatting that breaks configuration files.
If your FTP client shows file permissions, .htaccess usually needs 644. Too strict permissions can stop WordPress or plugins from updating it.
How do you edit .htaccess with a plugin?
Some SEO and file manager plugins include an .htaccess editor in the dashboard, which is handy when you have no FTP access, but a mistake can lock you out, so keep FTP or file manager access as a backup.
If the site breaks after saving, the plugin's editor may be unreachable. You would then need FTP or the file manager to fix it.
Only use well-maintained plugins for this. Editing server configuration from the dashboard is powerful and should be limited to administrators.
Where should you add custom rules?
Add your own rules above the BEGIN WordPress line or below the END WordPress line, never inside that block, because WordPress rewrites that section when permalinks are saved.
Plugins mark their own sections with similar BEGIN and END comments. Leave those sections alone too, and let the plugin manage them.
Order matters. Redirect rules usually need to come before the WordPress rewrite rules, so requests are redirected before WordPress handles them.
Add a comment above each custom rule explaining what it does and why. Comments start with a hash symbol.
How do you test a change safely?
Test changes on a staging site first when possible, then on the live site check the home page, a post, a page, the admin area and any URLs your rule affects.
Use a private browser window to avoid cached redirects. Browsers remember 301 redirects, so an old rule can seem to still work after you remove it.
Command-line tools such as curl with the -I option show the response headers and status code, which confirms exactly what the server sends back.
If you are unsure about a rule, add it, test it for a day, and keep the backup ready until you are confident it works everywhere.
What are the default WordPress rules?
The default block sends requests for files and folders that do not exist to index.php, which lets WordPress handle pretty permalinks; you can restore it by saving Settings > Permalinks.
The WordPress documentation on Apache server configuration shows the exact default rules for single sites and multisite.
If permalinks stop working, re-saving the permalink settings often fixes the file. Our guide on fixing permalinks not working covers other causes.
What are common .htaccess edits?
Common edits include 301 redirects, forcing HTTPS, adding security headers, blocking access to sensitive files, raising upload limits on some hosts and setting browser caching rules.
For simple redirects, a plugin is often safer than editing the file by hand. Our guide on setting up 301 redirects in WordPress compares the methods.
Security headers can be added in .htaccess on Apache. Our guide on adding security headers to WordPress shows examples.
MDN's reference on HTTP headers explains what each header does before you add it.
How do you fix a 500 error after editing .htaccess?
Restore your backup copy, or rename .htaccess to disable it, then reload the site; if it works, the error came from your change, so check the rule for typos or unsupported directives.
A 500 Internal Server Error right after saving almost always means a syntax error or a directive your host does not allow.
Your host's error log usually names the problem line. Check it before guessing.
Our guide on fixing the 500 internal server error covers other causes if restoring the file does not help.
How do you avoid redirect loops?
Test redirect rules in a private window, make sure a rule does not redirect a URL to itself, and avoid duplicating redirects that a plugin, Cloudflare or your host already applies.
Forcing HTTPS in .htaccess while a CDN also forces it, with mismatched settings, is a classic cause of loops.
Our guide on fixing the too many redirects error walks through the usual culprits.
Frequently asked questions
Where is the .htaccess file in WordPress?
It is in the WordPress root folder, alongside wp-config.php, wp-admin and wp-includes. It is hidden by default, so enable Show hidden files in your file manager or FTP client.
Why can't I find .htaccess?
Hidden files may be turned off, your server may be Nginx, which does not use it, or the file has not been created yet. Saving Settings then Permalinks can create it on Apache.
How do I restore the default WordPress .htaccess?
Replace the WordPress section with the default rules from the WordPress documentation, or delete the file and save Settings then Permalinks so WordPress creates a fresh one.
Can editing .htaccess break my site?
Yes. A single typo or unsupported rule can cause a 500 error. Always back up the file first, and restore the backup if the site stops loading.
Does .htaccess work on Nginx?
No. Nginx ignores .htaccess files. Rules must be added to the Nginx server configuration, which usually requires your host's help.
Sources
- Apache HTTP Server Tutorial: .htaccess files Apache HTTP Server Project
- Apache HTTPD / .htaccess WordPress Developer Resources
- HTTP headers MDN Web Docs
- nginx documentation nginx
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.


