htaccess & Redirects

301 Redirect

Updated September 2026 2,022 views 7 min read
htaccess & Redirects | Updated September 2026

A 301 redirect is a permanent redirect. It tells browsers and search engines that a page has moved for good, and it passes almost all of the old page's SEO value (link equity) to the new URL. This guide covers how to set up 301 redirects in .htaccess on your Ultra Web Hosting account, the most common patterns (old page to new, non-www to www, HTTP to HTTPS, whole-domain moves), and how to test them. If your move is only temporary, use a 302 redirect instead.

01. When to Use a 301 (vs a 302)

The number is the HTTP status code the server returns, and it tells search engines how to treat the move. Choosing the right one matters for SEO.

Temporary

302 Found (Temporary)

  • The move is temporary - the old URL will return
  • Does not pass link equity; the old URL keeps its ranking
  • Search engines keep the old URL indexed
  • Use for maintenance pages, A/B tests, short promos

Use a 301 for anything permanent: retiring an old page, moving to a new domain, forcing www or HTTPS. Use a 302 only when the original URL will genuinely come back. Using a 302 for a permanent move is a common SEO mistake - it stops the new URL from inheriting the old page's ranking.

02. Basic 301 Redirect

The Redirect directive (from Apache's mod_alias) is the simplest way to redirect a single page. Add it to the .htaccess file in your public_html folder (create the file if it does not exist):

One page to another

Redirect 301 /old-page.html https://yourdomain.com/new-page.html

An entire directory

Redirect 301 /old-folder https://yourdomain.com/new-folder

This moves /old-folder/anything.html to /new-folder/anything.html, preserving the rest of the path.

Tip

The source is always a path relative to your domain root (it starts with / and has no https://). The destination is always a full absolute URL. Mixing these up is the most common reason a redirect does not work.

03. Common 301 Patterns

Redirect an entire old domain to a new one

Put this in the .htaccess of the old domain to send every URL to the same path on the new domain:

RewriteEngine On
RewriteRule ^(.*)$ https://newdomain.com/$1 [R=301,L]

Force non-www to www

RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain\.com [NC]
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R=301,L]

Force www to non-www

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.yourdomain\.com [NC]
RewriteRule ^(.*)$ https://yourdomain.com/$1 [R=301,L]

Force HTTP to HTTPS

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Tip

Pick one canonical form (www or non-www, and always HTTPS) and redirect everything else to it. Running the same content on more than one address splits your SEO and can cause duplicate-content issues. For the combined HTTPS + www rule, see Redirect HTTP to HTTPS and www.

04. RewriteRule-Based 301s

When you need pattern matching rather than one-to-one rules, use mod_rewrite. The [R=301,L] flags make the rewrite an external 301 redirect and stop processing further rules.

A single page with RewriteRule

RewriteEngine On
RewriteRule ^old-page\.html$ https://yourdomain.com/new-page.html [R=301,L]

Redirect by pattern (regex)

Send every .php URL under /blog/ to the matching .html URL:

RewriteEngine On
RewriteRule ^blog/(.*)\.php$ /blog/$1.html [R=301,L]
Order Matters

Put your redirect rules near the top of .htaccess, above application rules (like the WordPress or WHMCS blocks). A rule with [L] stops processing, so a redirect placed after a catch-all rule may never run. Do not mix a Redirect (mod_alias) and a RewriteRule for the same URL - pick one method per redirect.

05. 301 Redirects and SEO

The main reason to get 301s right is search ranking. A correct 301:

  • Transfers link equity - the new URL inherits almost all of the old page's ranking signals and backlinks
  • Updates the index - search engines replace the old URL with the new one over time
  • Preserves bookmarks and inbound links - anyone with the old link still lands on the right page
  • Avoid redirect chains - A to B to C loses value and slows the page. Point every old URL directly at the final destination.
  • Redirect to the equivalent page - send an old page to its true replacement, not to the homepage. Mass-redirecting everything to the homepage is treated as a soft 404 and passes little value.
  • Update internal links too - after adding redirects, change your own menus and links to point at the new URLs so visitors and crawlers are not relying on the redirect.

06. Testing Your Redirect

After saving .htaccess, confirm the redirect returns a real 301 and lands on the right URL.

Command line (most reliable)

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

Look for HTTP/1.1 301 Moved Permanently and a Location: header pointing to the new URL. If you see 302, your rule used the wrong code.

Browser developer tools

Open DevTools (F12), go to the Network tab, enable "Preserve log," and load the old URL. The first request should show status 301 before the browser follows it to the new page.

Tip

Browsers cache 301s hard. If you are testing changes to a redirect, use an incognito/private window or curl - a normal browser tab may keep following the old cached redirect even after you fix the rule.

07. Troubleshooting

  • Redirect loop (ERR_TOO_MANY_REDIRECTS) - the target of your redirect also redirects back to the source. Most often caused by an HTTPS or www rule that matches its own destination. Add a RewriteCond so the rule does not fire on the already-correct URL.
  • 500 Internal Server Error after editing - a syntax error in .htaccess. Check for a missing RewriteEngine On, a typo in a flag, or a stray character. Restore the previous version and re-add rules one at a time.
  • Redirect not happening at all - the rule is below a catch-all [L] rule (move it up), or the source path is wrong (it must start with / and match the real URL), or the browser cached an earlier state (test with curl).
  • It redirects but shows 302 instead of 301 - you used Redirect 302 or omitted the code (mod_alias defaults vary), or a RewriteRule flag says [R] or [R=302] instead of [R=301].
  • Works locally but not through the CDN - if the domain runs through Cloudflare, purge the Cloudflare cache after changing redirects, since the edge may serve a cached response.

Need Help With a Redirect?

If a redirect will not behave - a loop, a 500 error, or a rule that just will not fire - open a ticket with your domain and the exact rule you added, and we will sort it out.

Open a Support Ticket

08. Frequently Asked Questions

What is the difference between a 301 and a 302 redirect?

A 301 is a permanent redirect: it tells search engines the page has moved for good and passes almost all of the old page's SEO value to the new URL. A 302 is temporary: the old URL is expected to return, so search engines keep it indexed and do not transfer ranking. Use 301 for permanent moves and 302 only when the original URL will come back.

How do I create a 301 redirect in .htaccess?

Add a line to the .htaccess file in your public_html directory. For a single page: Redirect 301 /old-page.html https://yourdomain.com/new-page.html. The source is a path starting with a slash and the destination is a full URL. Our servers read .htaccess automatically, so no restart is needed.

How do I redirect an entire domain with a 301?

In the old domain's .htaccess, add: RewriteEngine On, then RewriteRule ^(.*)$ https://newdomain.com/$1 [R=301,L]. This sends every URL to the same path on the new domain and preserves the rest of the address.

Do 301 redirects hurt SEO?

No - a correct 301 preserves SEO. It passes almost all of the old page's link equity to the new URL. To keep as much value as possible, redirect each old page to its true replacement (not the homepage), avoid redirect chains, and update your internal links to point at the new URLs.

Why does my redirect keep looping?

A redirect loop means the destination also redirects back to the source, usually from an HTTPS or www rule matching its own target. Add a RewriteCond so the rule only fires on the wrong version of the URL, and clear your browser or CDN cache before testing again.

Quick Recap

  1. Use 301 for permanent moves - it passes SEO value; use a 302 only for temporary ones
  2. One page: Redirect 301 /old-page.html https://yourdomain.com/new-page.html in .htaccess
  3. Patterns: use RewriteRule ... [R=301,L] for domains, www, and HTTPS
  4. Redirect to the real replacement - not the homepage - and avoid chains
  5. Test with curl -I - confirm you see 301, not 302

Last updated September 2026 · Browse all htaccess & Redirects articles · See also: 302 (Temporary) Redirect Guide | Complete Guide to .htaccess

Share: X in Reddit f Email
  • 2 Users Found This Useful

Was this answer helpful?

Related Articles

How to Create a Temporary 302 Redirect via htaccess

htaccess & Redirects | Updated March 2026 A 302 redirect sends visitors (and search...

Nginx and htaccess Redirect Issues

htaccess & Redirects | Updated March 2026 If your .htaccess redirects aren't working for...

Create a 410 Redirect for Missing Files

htaccess & Redirects | Updated January 2026 A 410 (Gone) status code tells search engines...

When I Upload an htaccess File It Disappears

htaccess & Redirects | Updated March 2026 Your .htaccess file is there. You just can't...

htaccess referral redirect

htaccess & Redirects | Updated January 2026 You can use .htaccess to redirect visitors...



Save 30% on web hosting - Use coupon code Hosting30