Ahosting Logo
Knowledge Base

How to Redirect a Domain or Page

A redirect sends a visitor from one address to another. The mechanics are simple; the decisions that matter are which type to use and whether you are redirecting to the equivalent page or dumping everything on a homepage.

301 or 302

301 Permanent. The address has moved for good. Search engines transfer ranking signals to the destination, and browsers cache the redirect so repeat visitors skip it entirely. This is what you want almost every time.

302 Temporary. The original will return. Nothing is transferred, and browsers ask again on every visit.

Choosing 302 by accident is common and quietly wasteful: the destination never inherits anything, so a page you moved permanently keeps its value stranded at an address nobody uses.

Use 302 only when the move genuinely is temporary. A maintenance page, a seasonal landing page.

Setting one up

In cPanel, open Redirects. Choose the type, the domain, the path, and the destination.

Two options are worth understanding.

Wildcard redirect sends everything under a path to the equivalent path at the destination. Right when a whole site or section moved with its structure intact.

Only redirect with www / without www narrows the rule to one hostname form. Leave it on all unless you have a specific reason.

Redirecting to the matching page, or to the homepageTo the matching pageEverything to the homepageThe visitorarrives at what they wantedarrives somewhere else and leavesSearch enginestreat it as a moveoften treat it as a soft 404Ranking signalscarried acrosslargely lostEfforta mapping, onceone lineChains cost time and single hops do not: redirect straight to the final address rather than through two intermediateones.

Redirect to the equivalent page

If content moved rather than disappeared, send each old address to its match.

Sending everything to the homepage is better than a 404 and considerably worse than a real match. A visitor following a link to a specific article and landing on a homepage has to find it again, and most will not. Search engines treat it as a page that is gone instead of one that moved.

When an entire site moved with its paths intact, the wildcard option handles this in one rule rather than dozens.

Redirecting a whole domain

To send an alternate domain at your main one, the domain must first point at this server. Its nameservers set here. Adding a redirect for a domain that resolves elsewhere does nothing at all, and that is the usual reason a redirect appears not to work.

Each redirected domain also needs its own certificate if anyone reaches it over HTTPS. Without one, a visitor typing the https:// form sees a browser warning before the redirect happens. Run AutoSSL for it after adding the domain.

Domain forwarding and URL masking deals with the domain-level case, including why masking is worth avoiding.

Redirects in .htaccess

cPanel writes these into .htaccess, and you can edit it directly for anything the interface will not express.

Redirect 301 /old-page.html /new-page.html
RedirectMatch 301 ^/blog/(.*)$ /articles/$1

Take a copy of the file before editing. A mistake here produces a 500 or a loop across the whole site, and having the original beside it turns a crisis into a thirty-second fix.

Order matters: rules are evaluated top to bottom, and a broad rule placed above a specific one will catch requests the specific one was meant to handle.

Avoid chains and loops

A chain is A redirecting to B, which redirects to C. It works, and each hop costs a round trip. When you move something twice, update the original rule to point at the final destination rather than adding another link.

A loop is two rules pointing at each other, and the browser gives up with a too-many-redirects error. The usual cause is a server rule forcing one hostname form while the application is configured for the other. Forcing HTTPS sets out settling that.

Check it worked

curl -I https://example.com/old-page.html

Confirm the status is 301 rather than 302, and that the location header points where you intended.

Test a deep path too, not just the one you configured. A rule that works at the root and mangles paths below it is common, and the symptom is a redirect that drops everything after the domain.

Moving an entire site to a different domain is the largest version of this, with one rule that outlasts the move. For that, see How to Move a Website to a New Domain.

Query strings, and what does not survive

A redirect moves the path. What happens to everything after the question mark depends on how the rule is written.

RewriteRule ^old-page$ /new-page [R=301,END]
RewriteRule ^old-page$ /new-page [R=301,QSA,END]
curl -sI 'http://example.com/old-page?ref=newsletter' | grep -i location

Without the appending flag the parameters are discarded, which silently breaks campaign tracking, affiliate references and any link that carried state. With it they are preserved and passed on.

Where the destination already carries its own parameters, appending combines both, which is usually what you want and occasionally produces a duplicate parameter worth checking.

Anything after a hash is never sent to the server at all, so a redirect cannot preserve or change it. The browser reapplies it to the destination on its own, which is why a link to a section sometimes lands in the right page at the wrong place.

Hundreds of redirects belong in a map

A site redesign produces a list, and a list written as individual rules becomes a performance problem, because every rule is evaluated on every request.

# redirects.txt
/old/about    /company/about
/old/pricing  /plans

RewriteMap redirects txt:/path/to/redirects.txt
RewriteCond ${redirects:%{REQUEST_URI}} !=""
RewriteRule ^ ${redirects:%{REQUEST_URI}} [R=301,END]

A map is looked up once rather than compared repeatedly, and the list stays readable and reviewable as a plain file.

Where server configuration is not available, the same idea works inside the application, matching against a stored table before serving a not found page. Either is better than several hundred lines of rules that nobody dares to edit. Planning redirects for a redesign goes into building the list.

Sometimes the right answer is not a redirect

Sending every removed page somewhere is a habit rather than a decision, and two cases deserve different treatment.

A page that is genuinely gone with no equivalent should say so. A gone response tells search engines to drop it deliberately rather than to keep checking, and it tells a visitor the truth instead of dropping them somewhere unrelated.

And redirecting a large number of unrelated pages to the home page is treated as a soft not found. It gives the visitor nothing, since they arrived looking for something specific, and it gains nothing in search either.

Redirect 410 /discontinued-product
curl -sI https://example.com/discontinued-product | head -1

The test is simple. If you cannot name the page a visitor would have wanted instead, a redirect is not the answer. Creating a custom error page covers where they land instead.

When the redirect and the page disagree

A redirect declares one address correct. A canonical tag inside the page declares another. When they disagree, the signals cancel out.

curl -sIL https://example.com/old-page | grep -iE '^location|^HTTP'
curl -sL https://example.com/old-page | grep -o 'rel="canonical" href="[^"]*"'

Follow the redirect and read the canonical at the destination. It should point at the destination itself, not back at the old address and not at a third address.

The common fault is a page that was copied along with its canonical tag, so a whole section of a site claims to be a single page. That is worth checking after any bulk move, since it is invisible to visitors and clear to a crawler.

Watch these steps on screen 1 clip · 0:48

Recorded on a real panel, no narration, captions on screen. Opens here without leaving the page and without an account. Every name, address and figure shown is made up for the recording.