Tutorials keep telling you to “add this line to your .htaccess file.” But when you open your WordPress folder, you can’t find it. Or you find it and aren’t sure what’s safe to change.
This guide explains exactly where the .htaccess file in WordPress lives, why it’s often hidden, what the default WordPress rules look like, and how to edit the file safely. You’ll also learn how to create a new .htaccess file, how to fix a broken one, and the most useful rules to add.
Table of Contents
What Is the .htaccess File?
.htaccess (short for “hypertext access”) is a configuration file read by the Apache web server, and by LiteSpeed, which understands the same rules. It controls how the server handles requests for your site, folder by folder.
WordPress uses it mainly for pretty permalinks: the rules that turn a URL like /blog/my-first-post/ into a request WordPress can understand. Without those rules, every page except your homepage would show a 404 error.
You can also use the .htaccess file in WordPress to:
- Set up 301 redirects
- Force HTTPS or a preferred domain
- Protect sensitive files such as wp-config.php
- Block access to certain folders or IP addresses
- Change some PHP settings on servers that allow it
- Add caching and compression rules (often written by caching plugins)
Important: If your server runs NGINX, there is no .htaccess file, and adding one does nothing. NGINX uses its own configuration, which only your host or server admin can change. Many managed WordPress hosts use NGINX.
Where Is the .htaccess File in WordPress?
The main .htaccess file in WordPress sits in your site’s root folder: the same folder that contains wp-config.php, wp-admin, wp-content and wp-includes.
On most hosts, that folder is called:
- public_html (cPanel and most shared hosting)
- www or htdocs (some hosts and local setups)
- A folder named after your domain, for addon domains or subdomains
If WordPress is installed in a subfolder (for example, public_html/blog/), the .htaccess file for that site is in the subfolder.
You may also find smaller .htaccess files inside other folders, such as wp-content/uploads/ or plugin folders. Security and caching plugins often add these. Leave them alone unless you know why they’re there.
Why Can’t I See the .htaccess File?
There are three common reasons.
1. It’s a Hidden File
On Linux servers, any file whose name starts with a dot is hidden by default. Your File Manager or FTP client may simply not be showing it.
In cPanel File Manager: Click Settings (top right), tick Show Hidden Files (dotfiles), and click Save.
In FileZilla: Open the Server menu and choose Force showing hidden files.
In other file managers: Look for an option called “show hidden files” or “show dotfiles.”
2. It Hasn’t Been Created Yet
WordPress only creates .htaccess when you save your permalink settings, and only if it has permission to write to the folder. On a brand-new site, it may not exist yet. See “How to Create or Reset .htaccess” below.
3. Your Server Doesn’t Use It
If your host runs NGINX, there won’t be a .htaccess file. You can check in Tools → Site Health → Info → Server, where Web server shows Apache, LiteSpeed or NGINX.
The Default WordPress .htaccess Rules
On a standard single-site installation, the .htaccess file in WordPress contains this block:
# BEGIN WordPress
<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
In plain English: if a request isn’t for a real file or folder on the server, send it to WordPress’s index.php, which works out which page to show.
The golden rule: WordPress manages everything between # BEGIN WordPress and # END WordPress, and may rewrite it whenever permalinks are saved. Put your own rules above or below this block, never inside it.
Multisite? WordPress Multisite uses a different set of rules. Copy them from Network Admin → Settings → Network Setup rather than from this guide.
How to Edit the .htaccess File in WordPress
Before you start: Always download a backup copy of .htaccess before editing it. A single typo can cause a 500 Internal Server Error across your whole site. With a backup, you can fix it in seconds.
Method 1: Using Your Hosting File Manager
- Log in to your hosting control panel and open File Manager.
- Open your site’s root folder (usually public_html).
- Make sure hidden files are visible (see above).
- Right-click .htaccess and choose Download to keep a backup.
- Right-click it again and choose Edit.
- Make your changes outside the WordPress block, then click Save Changes.
- Visit your site in a private browser window to check it still works.
Method 2: Using FTP or SFTP
- Connect to your site with an FTP/SFTP client such as FileZilla.
- Turn on Force showing hidden files.
- Open your site’s root folder and download .htaccess to your computer.
- Make a copy as a backup, then open the original in a plain text editor (such as Notepad, TextEdit in plain-text mode, or VS Code).
- Edit, save, and upload it back to the same folder, replacing the old file.
Tip: Don’t use a word processor like Word. It can add hidden formatting that breaks the file.
Method 3: Using an SEO Plugin’s .htaccess Editor
Some SEO plugins let you edit the .htaccess file in WordPress without leaving the dashboard:
- Rank Math: Go to Rank Math SEO → General Settings → Edit .htaccess. You may need to switch Rank Math to Advanced mode and enable editing.
- Yoast SEO: Go to Yoast SEO → Tools → File editor.
These editors are convenient, but if a mistake takes your site down, you’ll need File Manager or FTP to fix it. Keep a backup either way.
How to Create or Reset the .htaccess File
If the file is missing, or you suspect it’s corrupted, the easiest fix is to let WordPress regenerate it.
Let WordPress Create It
- Go to Settings → Permalinks in your dashboard.
- Without changing anything, click Save Changes.
WordPress writes fresh rules to .htaccess. If it can’t (because of file permissions), it shows the rules at the bottom of the page for you to copy manually.
Create It Manually
- In your site’s root folder, create a new file named exactly .htaccess (with the dot, and no .txt extension).
- Paste in the default WordPress rules shown above.
- Save the file.
- Go to Settings → Permalinks and click Save Changes.
Check File Permissions
The .htaccess file usually needs permissions of 644. In File Manager, right-click the file and choose Change Permissions (or Permissions). Avoid 777, which lets anyone write to it.
Useful .htaccess Rules for WordPress
Add these above the # BEGIN WordPress line. Add one rule at a time and test your site after each change.
Force HTTPS
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Many hosts and SSL plugins handle this already, so check before adding it. Doing it twice can cause a redirect loop.
Redirect a Single Page (301 Redirect)
Redirect 301 /old-page/ https://example.com/new-page/
For more than a handful of redirects, a plugin such as Redirection or Rank Math’s redirection manager is easier to manage.
Protect wp-config.php
<Files wp-config.php>
Require all denied
</Files>
Disable Directory Browsing
Options -Indexes
This stops visitors from seeing a list of files in folders that have no index page.
Block Access to xmlrpc.php
<Files xmlrpc.php>
Require all denied
</Files>
Only do this if you don’t use the WordPress mobile app, Jetpack or other services that rely on XML-RPC.
Change PHP Limits (Apache With mod_php Only)
php_value upload_max_filesize 128M
php_value post_max_size 128M
php_value memory_limit 256M
⚠️ On servers running PHP-FPM or FastCGI,
php_valuelines cause a 500 error. Use your hosting panel or .user.ini instead. See our guides on increasing the maximum upload file size and increasing the WordPress memory limit.
Rules That Plugins Add to Your .htaccess File
Open the .htaccess file in WordPress on almost any established site and you’ll find more than the default WordPress block. Many plugins write their own rules, each wrapped in its own BEGIN and END comments. It helps to recognize them so you don’t delete something important.
Caching Plugins
Plugins such as LiteSpeed Cache, WP Rocket and W3 Total Cache add rules for browser caching, compression and serving cached pages. These blocks can be long. Change cache settings inside the plugin rather than editing its rules by hand, because the plugin rewrites its block whenever you save its settings.
Security Plugins
Security plugins may add rules that block suspicious requests, protect sensitive files or limit access to the login page. If you remove or change these rules, you may switch off protection without realizing it.
SSL and Redirect Plugins
Plugins that force HTTPS or manage redirects sometimes write their rules to .htaccess. If you also add your own HTTPS redirect, the two can clash and cause a redirect loop. Use one method, not both.
What to Do With Old Plugin Rules
When you delete a plugin, its rules usually disappear too, but not always. If you see a block labelled with the name of a plugin you no longer use, download a backup of the file, remove that block, save, and test your site. If anything breaks, restore the backup.
A tidy .htaccess file in WordPress is easier to troubleshoot. As a rule of thumb, keep your own custom rules at the top of the file, clearly labelled with a comment such as # Custom rules, so you always know which lines you added yourself.
How to Fix .htaccess Errors
500 Internal Server Error After Editing
- Open File Manager or FTP.
-
Rename .htaccess to something like
.htaccess-broken. - Reload your site. If it works, the file was the problem.
- Go to Settings → Permalinks and click Save Changes to create a clean file.
- Re-add your custom rules one at a time, testing after each.
All Pages Except the Homepage Show 404
This usually means the WordPress rewrite rules are missing. Go to Settings → Permalinks and click Save Changes. If that doesn’t help, check that the default block is present in .htaccess.
Redirect Loop (“Too Many Redirects”)
You probably have two HTTPS or domain redirects fighting each other, for example one in .htaccess and one in a plugin or at your host. Remove one of them.
Changes Don’t Do Anything
Check whether your server uses NGINX (Site Health shows it). Also clear any caching plugin and your CDN cache, which may be serving old responses.
Frequently Asked Questions
Where is the .htaccess file in WordPress?
In your site’s root folder (usually public_html), alongside wp-config.php. It’s a hidden file, so turn on “show hidden files” in your File Manager or FTP client.
Does every WordPress site have a .htaccess file?
No. Only sites on Apache or LiteSpeed servers use it. Sites on NGINX don’t have one.
Is it safe to delete the .htaccess file?
Deleting it won’t damage WordPress, but your permalinks will break until you regenerate it under Settings → Permalinks. Any custom rules will be lost, so keep a backup.
Why does WordPress keep overwriting my changes?
WordPress rewrites the section between # BEGIN WordPress and # END WordPress. Put your custom rules outside that block.
Can a plugin edit .htaccess for me?
Yes. Rank Math and Yoast SEO include .htaccess editors, and caching and security plugins often add their own rules automatically.
What permissions should .htaccess have?
Usually 644. Avoid 777.
How do I edit the .htaccess file in WordPress without FTP?
Use your hosting File Manager in the browser, or an SEO plugin’s built-in editor such as Rank Math (General Settings → Edit .htaccess) or Yoast SEO (Tools → File editor). Both let you edit the .htaccess file in WordPress from your dashboard. Keep a backup copy in case you need to undo a change.
Can there be more than one .htaccess file in WordPress?
Yes. The main .htaccess file in WordPress sits in the root folder, but any folder can have its own. Rules in a subfolder’s file apply only to that folder. Plugins often place small .htaccess files in wp-content/uploads or their own folders to block direct access to files.
How do I restore the default .htaccess file in WordPress?
Rename the current file to keep it as a backup, then go to Settings → Permalinks and click Save Changes. WordPress writes a fresh .htaccess file in WordPress with the default rules. If it can’t write the file, copy the rules shown on that page into a new file yourself.
Does the .htaccess file in WordPress affect SEO?
Indirectly, yes. It controls your permalinks, redirects and HTTPS, which all matter for search engines. A broken .htaccess file in WordPress can cause 404 errors or redirect loops that hurt rankings, so test your site after every change.
Recommended Video Tutorials
- How to Edit Your .htaccess File in WordPress (Without Breaking Your Site), by StudioHawk: safe editing explained.
youtube.com/watch?v=tHb9J9183go
- How to Find and Edit Your WordPress .htaccess File, by GigaPress: locating and editing the file.
youtube.com/watch?v=R3nNJY3B064
- How to Edit .htaccess File via cPanel to Fix Common WordPress Errors, by RackNerd: fixing errors in cPanel.
youtube.com/watch?v=Gbl_iWzOS3I
Conclusion
The .htaccess file in WordPress is small but powerful. To recap:
- Find it in your site’s root folder, next to wp-config.php, with hidden files turned on.
- Back it up before every edit.
-
Add custom rules above or below the
# BEGIN WordPressblock, never inside it. - Regenerate it any time by saving Settings → Permalinks.
- If something breaks, rename the file and start fresh.
And remember: if your server runs NGINX, .htaccess doesn’t apply.
Don’t Want to Risk Breaking Your Site? Let Our WordPress Developers Help
Redirects, security rules and server settings are easy to get wrong, and one typo can take a site offline. At Unitedtheme, we offer professional WordPress development services: setting up redirects after a redesign, hardening security, configuring caching and server rules, and fixing errors quickly. Hire Unitedtheme’s expert WordPress developers and let us handle the technical side.
Official References
- WordPress Developer Resources – htaccess
- Apache HTTP Server – .htaccess files
- Apache HTTP Server – mod_rewrite
Keep Your WordPress Site Secure and Healthy, Every Month
Server rules, plugins and WordPress itself change constantly. With Unitedtheme’s WordPress care plans and retainers, our team looks after your site on an ongoing basis: updates tested safely, security hardening, backups, uptime monitoring and bug fixes. Explore Unitedtheme’s WordPress retainer plans and let us keep your site running smoothly.




Leave a Reply