Two small files control a lot of how a WordPress site behaves: wp-config.php and .htaccess. Attackers know this. A single extra line in either one can load malicious code on every page, or send your Google visitors to a spam site while you see nothing wrong.
In this guide I show what these files normally look like, the warning signs I check for, and how to search for them quickly.
Before you start
- Download a copy of both files first. In File Manager, right-click each file and choose Download. If you change something by mistake, you can put the original back.
- Turn on hidden files.
.htaccessstarts with a dot, so File Manager hides it unless you tick Show Hidden Files (dotfiles) under Settings.
Both files sit in your website folder, usually public_html. To read one, right-click it and choose View, which is safer than Edit because it can’t change anything.
What a normal wp-config.php contains
A normal wp-config.php is short and predictable. In order, you will usually see:
- Database settings:
DB_NAME,DB_USER,DB_PASSWORD,DB_HOST,DB_CHARSETandDB_COLLATE. - Eight security keys and salts, such as
AUTH_KEYandNONCE_SALT, each a long random string. $table_prefix, usuallywp_or a short variation.WP_DEBUG, normallyfalseon a live site.- Possibly a few extra settings added by your host or a plugin, such as
WP_MEMORY_LIMITorWP_CACHE. - At the very end:
require_once ABSPATH . 'wp-settings.php';
Nothing should come after that last line.
Warning signs in wp-config.php
- Code after
require_once ABSPATH . 'wp-settings.php'; - Functions that unpack hidden code:
eval(,base64_decode(,gzinflate(,str_rot13(orassert(. A normalwp-config.phpdoesn’t need any of them. - An
includeorrequireof a strange file, especially one disguised as an image or icon, like@include "/home/user/public_html/wp-content/uploads/favicon_8a3f.ico"; - One extremely long line of random-looking characters.
- A lot of empty space pushing code far to the right or far down, where you won’t notice it.
What a normal .htaccess contains
On most WordPress sites, .htaccess 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
You may also see blocks added by your host, such as one marked cPanel-generated handler that sets the PHP version, or blocks added by caching or security plugins, which usually name the plugin in a comment. Those are normal.
Warning signs in .htaccess
- Redirects that depend on where the visitor came from, for example rules containing
HTTP_REFERERwithgoogle,bingoryahoo. This sends search visitors to spam while you, typing the address directly, see the real site. - Rules that check for search engine bots, such as
HTTP_USER_AGENTwithgooglebot. The attacker shows Google a different page from the one people see. php_value auto_prepend_fileorauto_append_file. This forces a file to run before or after every page. Check the same setting in.user.iniandphp.inifiles too.AddHandlerorAddTypelines that make other file types run as PHP, for example letting a.jpgor.txtfile run as code.- A new
.htaccessin many folders at once that blocks everything except one oddly named PHP file. Attackers use this to protect their own files.
Search for the warning signs in one go
If you can use the Terminal (see my guide on opening the Terminal in cPanel and running WP-CLI), these commands do the checking for you. They only read; they change nothing.
cd ~/public_html
grep -nE "eval\(|base64_decode|gzinflate|str_rot13|assert\(" wp-config.php
grep -nE "auto_prepend_file|auto_append_file|HTTP_REFERER|HTTP_USER_AGENT|AddHandler|AddType" .htaccess
No output is a good sign. Any line that appears needs reading.
To check every .htaccess, .user.ini and php.ini file on the site for the auto-prepend trick:
find ~/public_html \( -name .htaccess -o -name .user.ini -o -name php.ini \) -exec grep -lE "auto_prepend_file|auto_append_file" {} +

If you find something
- Keep a copy of the infected file as evidence, outside
public_html. - Remove only the bad lines, or replace
.htaccesswith the standard WordPress block above. - Change the security keys. This logs everyone out, including the attacker:
wp config shuffle-salts --skip-plugins --skip-themes
- Change the database password in cPanel → MySQL Databases, then update
DB_PASSWORDinwp-config.phpto match. Anyone who could edit this file could also read it. - Find out how the attacker got in. An altered
wp-config.phpmeans someone could write files on your account. Cleaning the file without closing that door means it will happen again. My security series covers how I traced exactly that.
