A friend texts you: ‘Hey, I clicked your blog link and it took me to some casino site.’ Your stomach drops. You type your address into the browser, and your blog loads fine. Nothing odd. You try again on your phone and there it is, a page you have never seen, on a site that is not yours.

If your blog sends visitors to someone else’s website, it is almost always one of two things. Either someone put a redirect there without your permission, or a setting you made yourself is pointing the wrong way. The first is a security problem and needs a careful cleanup. The second is a simple fix once you find it. This guide helps you tell them apart and walk through both.

We will keep the steps in a sensible order: stay calm, confirm what is happening, find where the redirect lives, remove it, then close the door so it does not come back. The advice is based on guidance from WordPress.org, Google Search Central and Wordfence, and each part links to its source. Every site is different, so treat this as a map. If a step feels beyond you, ask your host or a security professional for help.

Key Takeaways:

  • A malicious redirect is code that sends your visitors to another site. Wordfence’s Wordfence guide to removing malicious redirects says attackers usually add it to generate advertising impressions, though some redirects do more damage.
  • Many owners never see it. Hackers often target only certain visitors, such as people coming from search engines or on mobile devices.
  • The code can hide in theme files, posts, widgets, JavaScript files or the .htaccess file, as the Wordfence guide describes.
  • Back up first, scan your site and your own computer, change every password and then remove the code. The WordPress.org guide for a hacked site covers these steps.
  • Ask Google to review your site after cleanup if it flagged a problem, as the Google Search Console Help page on the Security Issues report explains.

Why Your Blog Is Sending Visitors Somewhere Else

Before you touch anything, take a breath. The WordPress.org guide to hacked sites says it plainly: stay calm, because you can recover. It also says to document what you see, and that is a good place to start.

Two kinds of redirects

Not every redirect is an attack. Some are put there on purpose, and sometimes they are put there by you and then forgotten. Here is a quick way to sort them.

TypeWho set it upTypical sign
Planned redirectYou, a plugin or your hostYou moved a page or domain and forgot the old rule
Settings mistakeYou or a helperThe redirect started right after a setting or plugin change
Malicious redirectAn attackerVisitors land on spam, ads or scam pages, often only some of the time

Google’s Google Search Central guide to redirects explains that a permanent redirect tells search engines the new address should replace the old one, and a temporary redirect does not. That matters because a mistaken permanent redirect can confuse search results for a long time. A malicious one can do worse: it can send your hard-won readers to someone else.

Why attackers bother

Wordfence’s guide explains that attackers insert redirect code mainly to earn advertising impressions, though some redirects lead to more dangerous pages. Your blog has something they want: visitors. If your site has a weak password, an old plugin or an infected computer behind it, an attacker may use it as a free billboard.

The WordPress.org guide lists signs that your site may be compromised. They include being flagged by Google or Bing, a host disabling your site, readers reporting warnings from their antivirus tools, and unfamiliar users or actions on the site. A redirect can be one of these signs, or the first one you notice.

A laptop on a desk showing lines of code on the screen
Redirect code can hide in plain sight among thousands of lines of legitimate code. Photo: Negative Space, Wikimedia Commons, CC0.

Why you may not see it

Here is the tricky part. The Wordfence guide notes that most site owners do not know their site is redirecting visitors. They usually find out when a reader tells them. Google’s security help adds a reason: hackers often make changes visible only to certain visitors, such as people arriving from a search engine or using a certain browser, so the owner sees a normal site. Google suggests checking pages with its URL Inspection tool, which shows the page as Google sees it, and fetching pages from the command line with different referrer or user-agent settings.

So if a reader says your blog redirects and you cannot repeat it, believe the reader. Try opening your blog from a search result, from a different browser and on a phone with mobile data instead of your home network. Take notes with times and dates, since this helps if you need to ask your host for help.

What to do right now

  • Write down what you saw, when you saw it and what you changed recently, such as a new plugin or theme.
  • Do not delete anything yet.
  • Check Search Console for security messages if your site is verified there.
  • Run a full antivirus scan on the computer you use to manage the blog.
  • Tell your host. They may already know and can often help.
  • Make a fresh backup, even of the infected site, so you have a copy to work from.

Taking a backup of a hacked site feels odd, but the WordPress.org guide recommends a snapshot before cleaning, because cleanup can go wrong and you will want something to refer back to. Keep that copy offline and do not restore it later without cleaning it first.

Finally, decide how involved you want to be. If you are comfortable with files and settings, you can follow the steps below. If not, there is no shame in paying a professional. A site owner who calls for help early often saves more time than one who experiments for a weekend. If your blog earns income or holds reader data, that is another reason to ask for help quickly.

How to Confirm the Problem and Find Where It Lives

Now that you know what you are looking for, the next job is to confirm the redirect and find its hiding place. Think of it as detective work. You are looking for one odd line among thousands of normal ones.

Check Search Console first

If your blog is verified in Google Search Console, open the Security Issues report. The Google Search Console Help page on the Security Issues report explains that it lists hacked content and malware that Google found, shows which pages are affected and gives steps to fix each issue. It also says you can request a review once you have cleaned things up. Google lists several types of problem, including injected code, added pages and content injection, and each type comes with its own instructions.

Do not panic if the report is empty. A clean report does not prove you are safe, since Google may not have crawled the affected pages yet. Treat reader reports as evidence too.

Look in the usual hiding places

The Wordfence guide describes where redirect code often lives. Use this as a checklist.

WhereWhat to look forHow to approach it
Theme filesA script placed near the top of the page headerView the page source, find the script, then remove it from the theme file
Posts and pagesScripts inserted into the content of many postsEdit the posts, or use a database tool for bulk changes
WidgetsA script inside a text or custom HTML widgetOpen the widget area and remove it
JavaScript filesScrambled code added to the end of a script fileDownload the files and search for odd code
The .htaccess fileRules that redirect by browser or by referrerBack up the file, then compare it with a clean version
Ad networksA third-party ad service sending visitors elsewhereRemove ad networks one at a time to test
Fingers typing on a backlit laptop keyboard
Scan your own computer too, since stolen passwords often start on the machine you type on. Photo: Gre123gr, Wikimedia Commons, CC0.

Search for suspicious code

Google’s guide suggests searching your pages and files for words that often show up in malicious code, such as eval, base64_decode and unescape. These words are not bad on their own, since legitimate plugins use them too. The point is to find places that deserve a closer look. Search only a copy of your files, and if you are not sure whether a piece of code is safe, ask someone who knows.

Wordfence also describes a simple way to find scripts in a page: in the Chrome browser, put view-source: in front of your page address, then search the page for the word script. Look at what surrounds each script to work out which file it came from. Most scripts on a site are normal, so you are looking for ones you do not recognize.

Check the .htaccess file

The WordPress.org guide calls the .htaccess file one of the most common targets, along with files such as index.php, header.php, footer.php and functions.php. Wordfence adds that .htaccess rules can redirect people based on the browser they use or the site they came from, which explains why you might see nothing. Download a copy, keep a backup and look for rules you did not write. Be careful: a wrong edit can take your whole site offline.

Rule out your own settings

Before you blame an attacker, check the boring things. Look at your redirect plugin or SEO plugin for rules you forgot about. Check your domain settings at your registrar, since a domain forward or a wrong DNS record can send visitors elsewhere. Confirm your domain has not expired. Our guide on how to choose a domain name explains why keeping control of your domain matters. If a redirect plugin shows a rule you do not recognize, treat that as a sign someone else added it.

When you have found the cause, write down the file, the line and the time. You will want that record when you clean up, and again if the problem returns.

How to Remove a Malicious Redirect Safely

Once you know where the redirect lives, you can take it out. Go slowly. Hackers often leave more than one way back in, so removing a single line is rarely the end of the story.

Lock things down first

The WordPress.org guide recommends resetting access before you clean, so the attacker cannot undo your work. That means changing passwords for WordPress users, especially administrators, and also for your hosting account, FTP or SFTP, the database and any control panel. It also suggests generating new secret keys in the wp-config.php file, which logs out anyone currently signed in. Use long, unique passwords and a password manager.

Add a second step to your login. The CISA guidance on multifactor authentication explains that multifactor authentication asks for something more than a password, such as a code from an app or a text message. Even if someone steals your password, they cannot easily sign in without that second step. WordPress.org also suggests two-factor authentication in its guide.

Clean the code

  1. Make a backup of your files and your database.
  2. Remove the redirect code from theme files, posts, widgets or script files, depending on where you found it.
  3. Compare your .htaccess file with a clean one and remove rules you did not add.
  4. Reinstall WordPress core files, the wp-admin and wp-includes folders, from a clean download of the same version, using SFTP.
  5. Delete themes and plugins you do not use, and reinstall the ones you keep from trusted sources.
  6. Remove unknown users and check that no unknown admin accounts remain.

The WordPress.org guide gives an important warning about reinstalling. It says to use the same version your site already runs, because an older or newer version could break your site, and to copy files with an SFTP program instead of the reinstall button in the dashboard, since the dashboard installer often only overwrites files and hackers often add new ones. It also notes that wp-admin and wp-includes can be replaced safely, while wp-content holds your own themes, plugins and uploads and needs a more careful check.

A row of server racks inside a computer room
Your blog lives on a server somewhere, so your host is a partner in cleanup. Photo: Indrajit Das, Wikimedia Commons, CC BY-SA 3.0.

Know your limits

Wordfence says that if you cannot remove the redirect or work out how the code got in, you should get help. That is sound advice. The code may be one symptom of a deeper problem such as a backdoor, an old plugin with a weakness or a stolen password. Cleaning the visible redirect while the weakness remains is like mopping the floor with the tap still running.

Many hosts offer cleanup or restore tools, and some security plugins have free scanners. Quttera, GOTMLS, Wordfence and Sucuri are plugin scanners named in the WordPress.org guide, and VirusTotal and Sitecheck are listed as remote scanners. Use more than one, because each scanner looks for different things.

Restoring from a backup

If you have a backup from before the problem started, restoring it can save time. Make sure the backup is clean, since you do not want to bring the infection back. After restoring, change all passwords, update everything and scan again. Ask your host what backups they keep and how far back they go.

Ask Google to review your site

If Google flagged your site, the Security Issues report lets you request a review after you have fixed the problem. The Search Console Help page has a section on how long a review takes, so be patient. Do not request a review before you have cleaned everything, because a rejected request slows you down.

Keep Your Blog From Being Hijacked Again

Once the redirect is gone, the real work begins: making sure it does not come back. Most of this is routine care, the digital version of locking the door when you leave.

Habits that protect you

Google’s guide to preventing malware offers a security checklist. It tells owners to choose good passwords, to be careful with third-party content and ads, to keep their own computers free of viruses, and to contact their hosting company for support. For owners with server access it adds keeping software updated, backing up the .htaccess file, watching log files and using secure protocols like SFTP instead of plain FTP.

HabitWhy it helpsHow often
Update WordPress, themes and pluginsOld software is a common way inWeekly check
Use strong, unique passwordsStops guessing and reuse attacksSet once, review yearly
Turn on multifactor authenticationProtects you if a password leaksSet once
Back up files and databaseGives you a clean copy to restoreAutomatic, then test it
Remove unused plugins and themesFewer pieces to attackMonthly
Check Search Console messagesEarly warning from GoogleWeekly

Watch your site health

The Google guide suggests searching with the site: operator now and then, to see which pages Google has found on your site. If pages you never wrote appear, investigate. It also says the Security Issues report shows hacked pages Google identified, and that you can forward Search Console messages to your email so you hear quickly. Set that up today and you will not have to depend on a reader noticing a problem.

The WordPress.org guide also suggests registering with several webmaster tools, such as Google Search Console and Bing Webmaster, so you hear about problems from more than one search engine.

Two people looking at code on a laptop screen in an office
Two sets of eyes find problems faster, so ask a trusted friend or developer to review your site. Photo: Lbronn, Wikimedia Commons, CC BY-SA 4.0.

Be careful with ads, plugins and helpers

Wordfence points out that some ad networks have lax standards and may send visitors to unwanted pages even when your site is clean. If you use ads, choose providers carefully. Install plugins and themes from sources that have a track record, and delete the ones you stop using. Give helpers the lowest access they need, and remove their accounts when the job ends.

Protect your traffic while you recover

A redirect scare can hurt your visitors and your rankings, so tell your readers what happened if it lasted long. A short honest note builds trust. Then get back to publishing. Our guide to how to increase blog traffic has ideas for winning readers back, and if you manage your blog from a phone, read our tips on blogging from your phone so you can spot problems quickly while you are away from your desk.

Keep a short security log: what happened, what you changed and when. If the problem ever returns, that log will save hours. Review your user list and your passwords twice a year, and test that your backups really restore. A bit of routine care costs far less than another cleanup weekend.

Think of security as a small weekly chore rather than a one-time project. Put a reminder in your calendar, open the dashboard, apply updates, glance at Search Console and check that your latest backup exists. Ten minutes a week is enough for most small blogs. If several people publish on your site, agree on who handles updates, so nothing is left for someone else to do. A written list of who has access and why makes it much easier to spot an account that should not be there.

The most common mistake is treating a redirect as a one-time event. Sites that get hacked once are often targeted again if the weakness is still there, so finish the job: update, secure and monitor. That is how a scary Tuesday turns into a story you tell with a shrug.

Frequently Asked Questions

Can my blog redirect without being hacked?

Yes. A forgotten redirect rule, a plugin setting or a domain forward can send visitors elsewhere. Check your own settings first.

Why does the redirect only happen to some visitors?

Attackers often target certain visitors, such as people coming from search engines or using certain devices, so the owner may never see it. Google’s help pages describe this.

Will Google penalize my site?

Google may flag hacked content and warn visitors. After you clean the site, you can request a review in Search Console.

Should I delete my blog and start over?

Usually not. The WordPress.org guide notes that purging everything is not always possible and that you can reinstall parts of the site.

Final Thoughts

A redirect to someone else’s blog feels awful, but it is fixable. Stay calm, confirm what visitors see, find where the code lives, clean it, change every password and add the protections that stop a repeat.

Do one thing today: turn on multifactor authentication for your blog and your hosting account, then check your backups.