Skip to main content
+44 7575 472931[email protected]
HostAccentKnowledge BaseHosting, websites, SEO, and growth

301 Redirect htaccess Setup: Copy-Paste Examples 2026

Set up a 301 redirect htaccess rule with copy-paste examples for single pages, whole domains, www, HTTPS and trailing slashes, tested by our own team.

Web HostingShared HostingBeginner Guide
301 redirect htaccess rules with copy-paste examples for pages, domains, www and HTTPS, set up in 2026

A moved page or a retired URL can quietly drain traffic you spent years earning — and a broken link tells Google the content is simply gone. The fix is almost always a 301 redirect htaccess rule: one line that sends visitors and search engines to the correct URL while carrying most of your ranking value across. This guide hands you the exact syntax, copy-paste examples for every common scenario — single pages, whole domains, www, HTTPS, and trailing slashes — plus the quiet mistakes that sink rankings. No fluff, just the rules that work.

Quick Answer: A 301 redirect in .htaccess permanently points an old URL to a new one, passing roughly 90–99% of the original page's ranking signals to the destination. You place a Redirect 301 or RewriteRule line in the .htaccess file inside your site's root folder (usually public_html). Apache reads that file on every request, so the redirect works the instant you save — no server restart required.

We resolve 20 to 30 client issues a day, and misfired redirects are a familiar face in that queue. On a tuned stack like Hostaccent's, these rules apply the moment you save — but the logic is identical on any Apache server, so follow along wherever your site lives. Everything below comes straight from fixing those tickets, rewritten so you can do it yourself in a few minutes.

What a 301 Redirect in .htaccess Actually Does

A 301 status code means "moved permanently." When Apache sends it, browsers cache the new location and search engines transfer the old URL's authority to the destination. That's the whole point — you keep your rankings instead of starting from scratch on a fresh URL.

The .htaccess file is a per-directory configuration file Apache reads on every request. Two modules handle redirects. mod_alias gives you the simple Redirect and RedirectMatch directives. mod_rewrite gives you the more powerful RewriteRule engine. For a plain page-to-page move, mod_alias is enough. For pattern-based work — forcing HTTPS, matching a host, redirecting an entire domain — mod_rewrite is the tool you want.

Permanent redirects also consolidate signals. If three old URLs point at one new page, Google eventually treats them as a single, stronger address rather than three diluted ones. A clean 301 passes nearly all of the original page's authority, so there's rarely a reason to fear "losing link juice." You can read the exact status-code definition in the MDN documentation on the 301 Moved Permanently response.

Pro Tip: Never chain a 301 into another 301 into a 302. Each hop adds latency — often 100–300ms per redirect — and every extra step dilutes the signal a little. Point the old URL straight at the final destination, not at a middle stop.

301 vs 302 Redirect: Which One You Actually Need

Here's the short version: use a 301 for permanent moves and a 302 for temporary ones. Get this wrong and you either leak ranking value or accidentally freeze it on a page you're trying to retire.

A 301 tells search engines the change is forever — update the index, move the authority. A 302 says the change is temporary — keep the old URL indexed, it's coming back. So if you permanently move a page but use a 302, Google holds the old URL in its index and withholds most of the transfer. That one-digit slip in the status code can stall a migration for weeks.

When should you genuinely use a 302? Real temporary cases: an A/B test, a seasonal landing page, a maintenance holding page, or a geo redirect you'll reverse. Everything else — a renamed page, a merged blog post, an old product URL, a domain change — is a 301.

The 301 vs 302 redirect decision comes down to one question: "Am I ever bringing the old URL back?" If the answer is no, it's a 301. The redirect old page to new page scenario is almost always permanent, so 301 is your default.

Where to Find and Edit Your .htaccess File

Your .htaccess file lives in your site's root directory — usually public_html or www. It starts with a dot, which means it's hidden by default, so the first job is revealing hidden files.

In cPanel's File Manager, open Settings (top right) and tick Show Hidden Files (dotfiles). Open public_html, and .htaccess appears in the list. Right-click, choose Edit, and you're in. Over FTP with a client like FileZilla, enable "force showing hidden files" in the server menu, then download the file to edit it locally.

Two rules before you touch a single line. First, back it up — copy the current file to .htaccess.bak so a bad rule can't take your site offline. Second, the file is whitespace- and order-sensitive; a stray character can throw a 500 Internal Server Error in WordPress or a 403 Forbidden error across the whole directory in one save.

If your control panel shows no .htaccess file at all, that's normal on a fresh site — just create a blank plain-text file named exactly .htaccess (no extension). Hostaccent's Standard plan ships with cPanel and NVMe SSD storage, so the File Manager loads instantly and your edits apply without opening an SSH session — useful when you're mid-migration and need a redirect live right now.

htaccess Redirect Examples You Can Copy and Paste

These are the htaccess redirect examples you'll reach for most. Copy a block, swap in your own URLs, and save. Each rewrite block assumes mod_rewrite is enabled — on the vast majority of shared hosting, it already is.

Redirect a Single Old Page to a New Page

bash
## mod_alias — simplest single-page redirect
Redirect 301 /old-page.html https://example.com/new-page.html

The path on the left is relative to your domain root; the target on the right is the full URL. This is the cleanest way to redirect old page to new page when you're only moving a handful of URLs and don't need pattern matching.

Redirect an Entire Old Domain to a New Domain

bash
## Redirect every URL on the old domain to the new one, path intact
RewriteEngine On
RewriteCond %{HTTP_HOST} ^olddomain\.com [NC]
RewriteRule ^(.*)$ https://newdomain.com/$1 [L,R=301]

This preserves the full path, so olddomain.com/blog/post lands on newdomain.com/blog/post — not a lazy dump to the homepage. This is the correct redirect domain htaccess pattern for a rebrand or a domain move, and it's the one that protects your existing rankings.

Force HTTPS, and Pick www or non-www

bash
## Force HTTPS on every request
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

## Force non-www to www
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]

Pick one canonical version — www or non-www — and redirect the other. Running both without a redirect splits your ranking signals across two addresses Google reads as separate sites. A valid SSL certificate is a prerequisite for the HTTPS rule; every Hostaccent plan includes free Let's Encrypt SSL, so the HTTPS target actually resolves instead of throwing a certificate warning.

Add or Remove a Trailing Slash

bash
## Remove the trailing slash from URLs
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

Trailing-slash inconsistency creates duplicate URLs that compete with each other. Choose one style and enforce it site-wide. For the full directive reference — flags, conditions, backreferences — the Apache mod_rewrite documentation is the canonical source and worth bookmarking.

Insider Insight: Test every rule in an incognito window, never your normal browser. Browsers cache 301s aggressively — once yours has seen the redirect, it may keep firing even after you fix a typo, tricking you into thinking the rule is still broken. Incognito ignores that cache and shows you the real behaviour.

Common 301 Redirect Mistakes That Break SEO

Most redirect damage isn't from the syntax — it's from the strategy. Here are the errors that land in the ticket queue again and again.

Redirecting everything to the homepage. When you retire pages, send each one to its closest relevant replacement, not a blanket rule dumping all traffic on /. Google reads a mass homepage redirect as a "soft 404" and quietly drops the ranking transfer you were counting on.

Redirect chains and loops. URL A → B → C forces three round trips and can spiral into a loop that ends in a browser error. Always point the original URL at the final destination in a single hop.

Using 302 for a permanent move. Covered above, but it's the single most common mistake we see — the syntax works, the page loads, and the ranking value simply never moves.

Forgetting your internal links. After redirecting, update your internal links to point at the new URLs directly. Redirects should catch external and legacy links, not paper over lazy internal linking that adds an extra hop to every click.

Breaking the file with a typo. One malformed line can trigger a 400 Bad Request error or take the whole directory down. That backup you made earlier is your one-click undo.

From the Ticket Queue: Across our monthly support volume, Linux server and config issues make up about 25% of tickets, and a large share of those trace back to a single bad .htaccess line. The fix is almost always restoring the backup and reapplying one rule at a time until the culprit shows itself.

Redirects matter most during a move. If you're migrating WordPress to a new host or moving from shared hosting to a Linux VPS, map your old URLs to new ones before you flip DNS — otherwise you strand every ranked page the moment the switch goes live. For a full breakdown of which 3xx code fits which scenario, the MDN guide to HTTP redirections is the clearest reference around.

Your Next Step: A Host Where .htaccess Just Works

The three rules that matter most: use 301 for permanent moves and 302 only for genuinely temporary ones; always redirect to the closest relevant page, never a blanket homepage dump; and point old URLs straight at the final destination so you never build a chain.

Now that you've got the 301 redirect htaccess rules down — single pages, whole domains, HTTPS, trailing slashes — the only thing left is a server that applies them cleanly and an SSL certificate that makes the HTTPS target resolve. You can wire that up yourself this weekend, or start on a stack where cPanel, NVMe SSD, free SSL, and daily backups are already in place.

Hostaccent has launched 10,000+ websites and handled 4,000+ migrations since 2012 (UK-incorporated 2018), and real engineers — not outsourced scripts — answer the support line. The Economy shared hosting plan$1.99/mo — covers a single site with everything you need to run redirects the second you save. Moving a brand and need the name too? Grab it in the same dashboard: register your .com$13.99/yr, one renewal date. Running heavier traffic or several client sites? Step up to Cloud Hosting$3.90/mo — or a Linux VPS$7.99/mo — where you control the full Apache config yourself.

One honest caveat: the Economy plan is sized for one site, so if you're juggling ten client projects, start on Cloud or VPS instead. Every plan carries a 30-day money-back guarantee and a 99.9% uptime guarantee, so what you see today is the price you keep at renewal.

Frequently Asked Questions About 301 Redirect htaccess

How do I set up a 301 redirect htaccess rule for a single page?

Add one line to the .htaccess file in your root folder: Redirect 301 /old-page.html https://example.com/new-page.html. Save the file and test in an incognito window. Apache applies it on the next request — no restart needed. Back up the file first so a typo can't take the site down.

What's the difference between a 301 and 302 redirect?

A 301 is permanent and transfers ranking value to the new URL; a 302 is temporary and keeps the old URL indexed. Use 301 for renamed pages, merged posts, and domain changes. Use 302 only for genuinely temporary situations like A/B tests or a short maintenance window.

Do 301 redirects hurt SEO or slow down my site?

A single, direct 301 passes roughly 90–99% of ranking signals and adds only 100–300ms of latency per hop. The harm comes from chains and loops, not the redirect itself. Keep every redirect to one hop and update internal links so visitors reach new URLs directly.

Why isn't my 301 redirect working?

The usual culprits: mod_rewrite isn't enabled, the rule sits below a conflicting one (order matters), a typo broke the file, or your browser cached the old behaviour. Test in incognito, check the rule order, and confirm RewriteEngine On appears once near the top of the file.

Can I redirect an entire domain with .htaccess?

Yes. Use a RewriteRule with a RewriteCond matching the old host, sending every path to the new domain: RewriteRule ^(.*)$ https://newdomain.com/$1 [L,R=301]. This preserves the full URL path instead of dumping everyone on the homepage, which protects your rankings during a rebrand.

Where is the .htaccess file on shared hosting?

It's in your site's root directory — usually public_html. Because the name starts with a dot, it's hidden, so enable "Show Hidden Files" in cPanel's File Manager to see it. On Hostaccent's shared plans the File Manager reveals and edits it right in the browser, with no SSH required.

Last updated

Jul 20, 2026

HostAccent Editorial Team publishes practical hosting guides, operations checklists, and SEO-focused tutorials for businesses building international web presence.

Discussion

Have a question or tip about this topic? Share it below — your comment will appear after review.

Your email stays private and is only used for moderation.

Write for the Community

Have a tutorial, tip, or insight to share? Get published on the HostAccent Blog with your name, bio, and website link.

Become a Contributor

Need a faster setup for this workflow?