WordPress
htaccess 500 Internal Server Error: The Usual Suspects and the Fix
An htaccess 500 internal server error looks like a disaster and is usually one bad line. Apache can't understand something in the file, so it refuses to serve anything at all, and every page on your site shows the same blank "Internal Server Error" message. The good news: the server writes down exactly which line it choked on.
On WordPress sites I see the same two culprits most often: php_value lines on servers running PHP-FPM, and old Apache 2.2 access rules like Order allow,deny. Both come from copying snippets out of older tutorials. Below is how to get the site back in two minutes, then how to find and fix the real line.
If the site is down and you'd rather not touch it, send me the details through the maintenance questionnaire. I reply with a plan and a fixed quote within one business day.
First, get the site back up (2 minutes)
Don't debug on a dead site. Restore it first, then investigate.
- Open your hosting File Manager (turn on "Show Hidden Files") or connect by SFTP.
- Rename
.htaccessin the WordPress folder to.htaccess-broken. Don't delete it. You need it to find the bad line. - Load the home page. If it works, the file was the problem.
- Log in to WordPress, go to Settings > Permalinks, and click Save Changes without changing anything. WordPress writes a fresh, default
.htaccessfile.
If WordPress can't write the file, create .htaccess yourself with the default block from the WordPress Apache documentation:
# Default WordPress rewrite block for a site in the domain's main folder.
# Restores pretty permalinks. Contains none of your custom rules, so add those back one at a time.
# BEGIN WordPress
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]
# END WordPressIf the site still shows a 500 error with the default file, .htaccess isn't your problem. Look at PHP errors, a full disk or the host instead. A blank page saying "There has been a critical error on this website" is a different error from a different layer: that's PHP, and WordPress critical errors have their own fix.
Read the error log: it names the line
Apache's own .htaccess guide says it plainly: when you get server errors, check the error log, and it will likely tell you which directive isn't allowed or which one has a syntax error.
Where to find it:
- cPanel: Metrics > Errors shows the most recent Apache errors for your account.
- Plesk: Websites & Domains > your domain > Logs, filtered to errors.
- VPS with SSH: the last lines of the Apache error log.
# Shows the 20 most recent Apache errors. Read-only.
# Ubuntu/Debian path first, AlmaLinux/Rocky path second.
sudo tail -n 20 /var/log/apache2/error.log
sudo tail -n 20 /var/log/httpd/error_logPut the broken file back for a minute, reload the page once to trigger the error, then rename it again. Now the log has a fresh entry pointing straight at your problem.
The usual suspects behind a 500 error after editing htaccess
Here's what the log lines usually say and what they mean.
| Error log says | What it means | Fix |
|---|---|---|
Invalid command 'php_value' or 'php_flag' |
PHP doesn't run as an Apache module on this server | Move the setting to .user.ini |
Invalid command 'Order' or 'Deny' |
Apache 2.2 access syntax, compatibility module not loaded | Rewrite with Require |
Options not allowed here |
The host doesn't let .htaccess change Options |
Remove the line, ask the host |
Invalid command 'Header' |
mod_headers isn't loaded | Wrap header lines in <IfModule mod_headers.c> |
RewriteCond: bad flag delimiters |
A typo, often curly quotes or a missing space | Retype the line by hand |
Request exceeded the limit of 10 internal redirects |
A rewrite rule matches its own result forever | Add a condition that stops the loop |
Failed opening required ... wordfence-waf.php |
A firewall setting points to a path that no longer exists | Fix or remove auto_prepend_file |
1. php_value on a PHP-FPM server
This is the classic. A tutorial says to raise the upload limit with php_value upload_max_filesize 64M in .htaccess. PHP's manual describes these directives only for the case when PHP runs as an Apache module, the old mod_php setup. Most hosts now run PHP-FPM (a separate PHP service Apache hands requests to), and on those servers Apache has no idea what php_value means. LiteSpeed's own documentation confirms that these directives are only supported by Apache's mod_php handler, and shows the resulting Invalid command 'php_flag' error. LiteSpeed servers, for what it's worth, accept the lines without the error.
Not sure which setup you have? WordPress shows it under Tools > Site Health > Info > Server, as "PHP SAPI". apache2handler means mod_php. fpm-fcgi or cgi-fcgi means php_value will break.
The fix is a .user.ini file in the WordPress folder. PHP reads it on CGI and FastCGI setups, which includes PHP-FPM:
; .user.ini replaces php_value lines from .htaccess on PHP-FPM hosts.
; Takes effect within 5 minutes (PHP's default re-read interval). Your host may cap the values.
upload_max_filesize = 64M
post_max_size = 128M
memory_limit = 256MFor memory specifically, WordPress has its own setting too, which I cover in the guide to raising the WordPress memory limit.
2. Apache 2.2 access rules
Rules like these fill old security tutorials:
# OLD Apache 2.2 syntax. Causes "Invalid command 'Order'" when mod_access_compat isn't loaded.
<Files wp-config.php>
order allow,deny
deny from all
</Files>Apache 2.4 replaced them with Require. Its upgrade notes say the old directives work only through a compatibility module, and that mixing old and new styles in the same configuration can give unexpected results. That mix doesn't always cause a 500. Sometimes it quietly causes a 403 (access denied) on a page that should load, which is harder to spot. Here's the modern version:
# Apache 2.4: deny web access to wp-config.php. Works without any compatibility module.
<Files "wp-config.php">
Require all denied
</Files>My Apache 2.4 .htaccess template for WordPress has every common rule rewritten this way.
3. Directives your host doesn't allow
Shared hosts decide which directive groups .htaccess may use, through a setting called AllowOverride. Options -Indexes is the classic example: perfectly valid, but forbidden on some hosts, giving Options not allowed here in the log. Remove the line and ask support to switch off directory listings for you. Most will.
4. Header lines without mod_headers
Header set ... lines need the mod_headers module. If it's missing and the line isn't wrapped in <IfModule mod_headers.c>, Apache stops. The wrapper makes Apache skip the block instead of failing, though it also means your headers silently don't apply. Check with curl -sI https://example.com/ afterward.
5. Curly quotes and invisible characters
Copying rules from a Word document, a PDF or some blog themes can swap straight quotes (") for curly ones (“ and ”), or add invisible non-breaking spaces. To Apache, a curly quote is just a strange character in the middle of a rule. Paste into a plain-text editor (Notepad, TextEdit in plain text mode, VS Code) first, and if a line looks right but fails, retype it by hand.
6. Rewrite loops
A rule like RewriteRule ^(.*)$ /new/$1 [L] also matches /new/whatever, so Apache rewrites it again, and again. After 10 rounds it gives up with a 500 and logs the internal redirect limit (set by LimitInternalRecursion). Add a condition that excludes the target, such as RewriteCond %{REQUEST_URI} !^/new/.
7. A firewall path from a previous server
Wordfence's Extended Protection adds an auto_prepend_file line, in .htaccess or .user.ini, pointing to a file on the server. Move the site to a new host and that path often doesn't exist anymore, so PHP fails on every request. Correct the path or delete the line, then re-run the optimization. My Wordfence setup walkthrough explains the safe order for migrations.
A quick test: is .htaccess being read at all?
Apache's documentation suggests a neat trick. Add a nonsense word, such as TestMe, on its own line in .htaccess and reload. If you get a 500 error, Apache reads the file. If nothing happens, your host ignores .htaccess (for example, an Nginx server) and none of your rules were ever active. Remove the word right after.
Final thoughts
A 500 error from .htaccess is loud but rarely serious. Rename the file, get the site back, read the log line, fix that one directive, then add your custom rules back one block at a time. The worst outcome is usually a few minutes of downtime and a lesson about copying 2015 tutorials.
If you'd like someone else to make server changes on a staging copy first and watch the live site afterward, that's part of my monthly WordPress upkeep.
htaccess 500 internal server error FAQs
Why do I get a 500 error after editing .htaccess?
Because Apache found a line it can't process, so it refuses to serve any page. The most common causes are php_value lines on servers running PHP-FPM, old Order allow,deny rules, directives the host doesn't allow, and typos such as curly quotes. The server's error log names the exact directive, so check it before changing anything else.
How do I fix a 500 internal server error in WordPress fast?
Rename .htaccess to .htaccess-broken with your host's File Manager or SFTP, then reload the site. If it loads, log in and save Settings > Permalinks to create a fresh default file. Then add your custom rules back one block at a time, reloading after each, until you find the line that breaks it.
Can I use php_value in .htaccess?
Only if PHP runs as an Apache module (mod_php) or the server runs LiteSpeed. On PHP-FPM, which most hosts use today, php_value and php_flag cause a 500 error. Use a .user.ini file in the site's main folder instead, or change the values in your hosting panel's PHP settings. WordPress Site Health shows your PHP setup under "PHP SAPI".
Where do I find the error log on cPanel?
In cPanel, go to Metrics > Errors to see the latest Apache errors for your account. Many cPanel hosts also write PHP errors to a file named error_log inside the folder where the error happened, often the WordPress folder itself. Reload the broken page once, then check both places for a fresh entry with the current time.
Still stuck, or the site is a store losing orders? Tell me what you're seeing and I'll take a look.
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.