Redirecting websites the right way means using 301s on purpose and auditing for hidden ones. Learn how to tell your redirects from a hacker's.
Redirecting websites is one of the most ordinary jobs in web management. You move to a new domain, change a URL, or merge two sites, and you send visitors and Google from the old address to the new one. It is also one of the most common tricks hackers use against small business sites. The mechanism is identical. Only the intent differs. This guide covers how to redirect a website properly, and how to check that every redirect on your site is one you put there.
The Redirects You Actually Want
A redirect tells the browser, or a search crawler, that the page it asked for lives somewhere else. The server answers with a status code and a destination. Two codes cover almost every legitimate case.
- 301 (permanent): the page has moved for good. Use it for domain changes, HTTP to HTTPS, www to non-www, and retired pages that have a clear replacement.
- 302 (temporary): the move is short-term, such as a page under maintenance or a seasonal landing page. Search engines keep the original URL as the main one.
- Meta refresh and JavaScript redirects: they work, but they are slower and less reliable for search. Use them only when you can't set a server-level redirect.
Google's own guidance says to use server-side permanent redirects when you move a page, and to keep them in place for a long time, at least a year where possible. The MDN guide to HTTP redirections explains how each status code behaves if you want the technical detail.
How to Redirect a Website Without Losing Rankings
Most ranking damage from redirects comes from sloppy mapping, not from the redirect itself. Sending every old URL to the home page is the classic mistake. Google treats it as a soft 404, and visitors land on a page that has nothing to do with what they clicked. Follow this order instead:
- Export every old URL that matters: top pages from Google Search Console, pages with backlinks, and pages that bring in leads.
- Map each one to its closest equivalent on the new site, one to one.
- Set the 301s at the server level (in .htaccess, Nginx config, or your host's redirect tool) rather than stacking plugins.
- Avoid chains. A to B to C wastes crawl time and breaks easily. Point A straight to C.
- Test a sample of URLs with a header checker, then watch Search Console's indexing reports for a few weeks.
- Leave the redirects live for at least a year.
If you are moving a WordPress site, keep a copy of your redirect rules in a document you control. When a redirect list lives only inside a plugin, nobody notices when an extra line gets added.
When Redirecting Websites Is a Hack
Attackers love redirects because they are cheap and quiet. After breaking into a site, they plant code that sends visitors to pharmacy spam, fake tech-support pages, or phishing sites. The code is usually written to hide from you. Common patterns include:
- Redirects that fire only for visitors arriving from Google, not for people typing your address directly.
- Redirects that skip logged-in admins, so you never see them yourself.
- Redirects that target mobile visitors only.
- Rules injected into .htaccess, the theme's header.php, or a database option, often with a random-looking filename.
- A rogue plugin or a modified core file that reloads the malicious code after you delete it.
A redirect you didn't write is not a quirk. It is a break-in that has already happened.
If customers report being sent somewhere strange but you can't reproduce it, that conditional behaviour is the clue. Our guide on why redirected websites send visitors elsewhere walks through the usual causes, and website redirecting to another site shows how to diagnose it before Google flags you.
A Quick Redirect Audit You Can Run Today
You don't need special tools to catch the obvious cases. Spend twenty minutes on this:
- Open your site in a private window on your phone, using mobile data, after finding it through a Google search. Click through a few pages.
- Open .htaccess in your site's root folder and read every rewrite rule. Anything you don't recognize, or any rule pointing to a domain you don't own, is a red flag.
- Review your redirect plugin's rules, if you have one, and check who last edited them.
- Check Google Search Console for security issues and manual actions.
- List your admin users and installed plugins. Remove anything you didn't add.
Found something suspicious? Don't just delete the line. Reinfection is the norm when the backdoor stays behind. See how to undo a website redirect and tell a harmless one from a hack before you change anything, and take a backup first so you have evidence of what was there.
When to Bring in a Professional
If your audit turns up redirects you didn't create, or if they come back after you remove them, the redirect is only the symptom. The real fix is finding the entry point: an outdated plugin, a stolen password, or a hidden admin account. That means scanning every file and database table, removing the backdoors, patching the hole, and then asking Google to review the site. That is the work behind our website malware removal service, and it is where a DIY cleanup most often falls short.
The takeaway: redirect on purpose, document every rule, and review the list on a schedule. A redirect you can explain is an asset. One you can't explain needs investigating now, before your rankings and your customers' trust pay for it.
References
This article is general educational information, not professional, medical, or purchasing advice. External links are provided for reference; DS Web Solutions Inc. is not affiliated with and does not endorse any third-party brand or organization listed.



