How to Do a 301 Redirect: Step-by-Step Guide

Browser address redirecting permanently from an old URL to a new URL

A 301 redirect permanently sends visitors and search engines from one URL to another. It is the right choice when a page has moved for good, a domain has changed, or several versions of a URL need to resolve to one preferred location. Done correctly, it prevents users from landing on broken pages and helps transfer ranking signals from the old URL to the new one.

Learning how to do a 301 redirect depends on where your website is hosted and which server or content management system it uses. An Apache site may use an .htaccess rule, while an Nginx server requires a configuration change. WordPress users can often create redirects with a plugin, and platforms such as Shopify provide built-in tools.

This article explains each of those methods with practical examples. You will also learn how to plan URL mappings, test redirects, avoid chains and loops, troubleshoot common errors, and choose the correct redirect type. Before changing server files, create a backup and confirm that you can restore the previous configuration if a rule behaves unexpectedly.

What a 301 Redirect Does

A 301 redirect is an HTTP response that tells a browser or crawler that a resource has moved permanently. When someone requests the old address, the server returns a 301 status code and a Location header containing the destination. The browser then requests the new URL.

For search engines, the permanent status is an important instruction. It indicates that the destination should replace the old address in the search index over time. Search engines can also consolidate many of the old page’s signals with the new page, provided that the destination is relevant and accessible.

Suppose a website originally published a service page at:

https://example.com/web-design-services

The company later simplifies the address to:

https://example.com/web-design

A properly configured redirect takes anyone visiting the first address directly to the second. Links, bookmarks, advertisements, and search results pointing to the former URL continue to work while the updated page becomes the preferred version.

A redirect differs from forwarding performed with JavaScript or a meta refresh tag. Those browser-level techniques may work for visitors, but they are less reliable for crawling and indexing. A server-side 301 response is normally the clearest way to communicate a permanent move.

When to Use a 301 Redirect

Use a 301 when the change is intended to be permanent and a suitable destination exists. Common situations include changing a page slug, restructuring site folders, merging overlapping articles, moving from HTTP to HTTPS, and migrating an entire website to a different domain.

A redirect is also useful for consolidating inconsistent URL versions. For example, a site may be accessible with and without “www,” or with uppercase and lowercase paths. Selecting one canonical format and permanently redirecting the alternatives reduces duplication and gives users a consistent address.

Appropriate uses include:

  • Replacing an outdated page with an updated version
  • Moving content to a new permanent URL
  • Combining two similar articles into one stronger resource
  • Redirecting an old domain after a rebrand
  • Enforcing HTTPS across the website
  • Removing file extensions from page addresses
  • Correcting a misspelled slug that has already received traffic or links
  • Sending discontinued product URLs to close replacements
  • Standardizing trailing-slash or hostname conventions

Do not automatically redirect every deleted page to the homepage. When no relevant replacement exists, returning a 404 or 410 response is often more accurate. An unrelated redirect frustrates visitors and may be treated by search engines as a soft 404 rather than a meaningful page move.

Preparing the Redirect Before Making Changes

Start by recording the exact source and destination. The source is the URL being replaced, while the destination is the final page visitors should reach. Check protocol, hostname, path, capitalization, query parameters, and trailing slashes because server matching rules can be sensitive to these details.

Open the intended destination before creating the rule. It should return a successful 200 response, contain content that satisfies the same or closely related intent, and not redirect somewhere else. Sending an old URL into an existing redirect creates an avoidable chain.

For a small update, a two-column mapping is enough:

Old URL: https://example.com/old-page

New URL: https://example.com/new-page

For migrations involving many pages, use a spreadsheet with the old URL, new URL, reason for the change, implementation status, test result, and notes. This becomes a useful record for developers, editors, and later audits. A well-maintained map also reduces accidental omissions.

Review traffic, backlinks, conversions, and search visibility before deleting or merging content. High-value URLs deserve individual, closely matched destinations. You can learn more about preserving important pages during a move in [Internal Link: Website Migration Checklist].

A practical pre-launch checklist includes:

  • Back up the server configuration and website files
  • Export or crawl the current URL list
  • Confirm that every destination loads correctly
  • Match old pages to relevant new pages
  • Remove duplicate or conflicting rules
  • Decide whether query strings must be preserved
  • Prepare a rollback method
  • Schedule testing immediately after deployment
  • Record the date each redirect goes live

Creating a 301 Redirect in Apache With .htaccess

Apache websites commonly support redirects through an .htaccess file located in the document root, often the same directory as the home page. Because this filename begins with a period, some file managers hide it by default. Enable hidden-file visibility before assuming it does not exist.

Download a backup before editing the file. A missing character or invalid directive can cause a 500 Internal Server Error across the site. Add focused rules near existing rewrite instructions, taking care not to interfere with rules generated by a content management system.

Redirecting One Page With mod_alias

For a simple one-to-one move on the same domain, the

Redirect 301 /old-page https://example.com/new-page

The source usually contains only the path, while the destination should be an absolute URL. Place more specific rules before broad directory rules. After saving the file, request the old page in a private browser window and inspect its status with a redirect checker.

Be cautious with prefix matching. Depending on the directive and path used, a rule intended for one location may also affect addresses beneath it. When exact matching or more complicated patterns are required, mod_rewrite gives you greater control.

Redirecting a Page With mod_rewrite

A basic mod_rewrite rule looks like this:

RewriteEngine On

RewriteRule ^old-page/?$ https://example.com/new-page [R=301,L]

The optional slash expression allows both /old-page and /old-page/ to match. The R=301 flag sets the permanent status, and L tells Apache to stop processing later rules after this one succeeds.

In a root-level .htaccess file, the RewriteRule pattern normally excludes the opening slash. That detail causes many failed implementations. Test with the actual server rather than copying a rule blindly, as hosting configurations and directory contexts can differ.

Redirecting an Entire Domain in Apache

A domain migration should preserve page paths whenever the new website uses the same structure:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?oldsite\.com$ [NC]

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

A request for oldsite.com/services would therefore go to newsite.com/services. The NC flag makes the hostname comparison case-insensitive. Escaped periods in the condition mean literal dots rather than wildcard characters.

Only use path preservation when equivalent pages actually exist on the new domain. If the structure changed, create individual mappings for priority pages or use carefully designed pattern rules. Sending every old path to the new homepage weakens relevance and creates a poor visitor experience.

Setting Up a 301 Redirect in Nginx

Nginx does not use .htaccess files. Redirects are added to the server configuration, which may be stored in nginx.conf or a site-specific file under a directory such as sites-available. You normally need server access and permission to reload the service.

For one page, an exact-match location is clear and

location = /old-page {

return 301 https://example.com/new-page;

}

The equals sign limits the rule to that exact path. Without it, broader location matching may capture URLs you did not intend to redirect. Include separate handling when both slash variants need to work.

For a complete domain move with the same path structure,

server {

listen 80;

server_name oldsite.com www.oldsite.com;

return 301 https://newsite.com$request_uri;

}

The $request_uri variable carries the path and query string to the destination. A request for /products/item?color=blue retains those components. Make sure the old domain’s HTTPS traffic is also handled with a valid certificate and an appropriate TLS server block.

Before reloading Nginx, validate the configuration:

nginx -t

If the test succeeds, reload the service using the command appropriate for your environment, such as:

sudo systemctl reload nginx

Do not reload after a failed configuration test. Correct the reported syntax or file-reference error first. Managed hosting customers may need to ask their provider to add Nginx rules because direct configuration access is often restricted.

Apache and Nginx Redirect Comparison

| Requirement | Apache | Nginx |

|—|—|—|

| Common configuration location | .htaccess or virtual host file | nginx.conf or site server block |

| Simple directive | Redirect 301 | return 301 |

| Pattern-based rules | RewriteRule and RewriteCond | location or rewrite |

| Per-directory configuration | Often available | Not supported through .htaccess |

| Validation method | Depends on hosting setup | nginx -t |

| Applying changes | Often immediate for .htaccess | Usually requires a reload |

| Typical access level | FTP, file manager, or server access | Server or hosting-panel access |

Using the simplest directive that meets the requirement makes future maintenance easier. Reserve regular expressions and conditional logic for cases that cannot be handled reliably with exact rules.

Adding a 301 Redirect in WordPress

WordPress users can create redirects with a plugin, through hosting tools, or at the server level. A reputable redirect plugin is convenient when editors need to manage individual URL changes without modifying configuration files. It may also log hits and identify visits to missing pages.

A typical workflow is straightforward:

1. Back up the website and database.

2. Install and activate a trusted redirect-management plugin.

3. Open the plugin’s redirect settings.

4. Enter the old path, such as /old-page/.

5. Enter the destination, such as /new-page/.

6. Select a 301 permanent redirect if the plugin offers status choices.

7. Save the rule.

8. Test the source URL while logged out.

Use relative paths for internal redirects when the plugin recommends them. Avoid installing multiple redirect or SEO plugins that manage the same rules because overlapping behavior can make troubleshooting difficult. Some SEO plugins already include a redirect manager, particularly in paid editions.

Server-level rules may be faster and remain independent of WordPress, but they require more technical access. Plugin-based rules are usually easier for editorial teams. The best option depends on who maintains the site, how many rules are needed, and whether redirects must function when WordPress itself is unavailable.

Creating Redirects in Shopify and Other Hosted Platforms

Shopify includes a URL redirect feature in the administration area. The precise navigation can change as the interface evolves, but it is generally found within website navigation or URL redirect settings. Enter the old path in the source field and the new path or full URL in the destination field.

Shopify may automatically create a redirect when a product or page handle changes, provided the relevant option is selected. Verify the result rather than assuming it was added. Redirects generally cannot override active routes, so the source address may need to be unused before the rule works.

Other hosted website builders often provide similar controls. Look for settings named URL redirects, redirects, forwarding, or SEO tools. The platform handles the HTTP response, so direct server access is unnecessary. If no redirect feature exists, contact the provider instead of relying on JavaScript.

Quick tips for content management systems:

  • Test while logged out to avoid administrative caching or preview behavior
  • Enter paths in the format required by the platform
  • Check whether the tool preserves query parameters
  • Export redirect lists when the platform supports it
  • Remove obsolete duplicate rules
  • Keep redirects after deleting the old content
  • Confirm that imported bulk rules use the correct column order
  • Recheck redirects after changing themes, apps, or routing settings

Choosing Between 301, 302, 307, and 308 Redirects

A 301 is intended for permanent moves. A 302 indicates a temporary redirect, meaning the original address is expected to return. Temporary status is useful for short campaigns, maintenance, location testing, or a limited change where the source should remain the primary URL.

Status codes 307 and 308 provide stricter method-preservation behavior. A 307 is temporary, while a 308 is permanent. They are particularly relevant when requests may use methods such as POST, because clients should not change the request method when following these redirects.

| Status | Meaning | Typical use |

|—|—|—|

| 301 | Moved permanently | Permanent page or domain change |

| 302 | Found or temporary move | Short-term substitution or test |

| 307 | Temporary redirect with method preserved | Temporary API or form endpoint move |

| 308 | Permanent redirect with method preserved | Permanent API or method-sensitive move |

For ordinary web pages reached with GET requests, 301 remains the familiar permanent option. For APIs, forms, checkout flows, and other method-sensitive routes, consult the application’s requirements before choosing a code. A careless redirect can change request behavior or interfere with submitted data.

Testing a 301 Redirect Correctly

Typing the old URL into a browser confirms that a visitor reaches the destination, but it does not prove the response is a 301. Browsers also cache permanent redirects, which can hide later changes. Use an HTTP inspection tool, command-line request, or redirect-checking service to view the complete response chain.

With curl, request only the headers:

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

A correct response should show a 301 status and a Location header containing the intended destination. To follow the chain and inspect the final result, use:

curl -IL https://example.com/old-page

The ideal sequence is usually one 301 response followed by a 200 response. Test HTTP, HTTPS, www, non-www, slash, and non-slash variants when those forms are relevant. Also test URLs with query parameters if tracking codes, filters, or campaign data need to survive the redirect.

After a large migration, crawl the old URL list in bulk. Look for incorrect destinations, redirect loops, chains, 404 responses, and server errors. Continue monitoring analytics, server logs, and search-console reports because problems can emerge only when search crawlers or old external links request less obvious URLs.

Testing checklist:

  • The old URL returns 301 rather than 200, 302, 404, or 500
  • The Location header points to the correct destination
  • The destination returns 200
  • No intermediate redirect is present
  • The final page matches the old page’s purpose
  • HTTPS works without certificate warnings
  • Query strings behave as intended
  • Mobile and desktop requests reach the same appropriate resource
  • Internal links use the final URL
  • Canonical tags reference the preferred destination

Common 301 Redirect Mistakes

Redirect chains occur when one URL redirects to a second URL, which then redirects to a third. Visitors may barely notice a short chain, but each extra request adds latency and creates another failure point. Update the first rule so it points directly to the final page.

A redirect loop is more serious. It happens when URL A sends traffic to URL B and URL B sends it back, or when conflicting protocol, hostname, and slash rules repeat indefinitely. Browsers typically display a “too many redirects” error after stopping the cycle.

Other frequent errors include:

  • Redirecting every removed page to the homepage
  • Choosing a destination with unrelated content
  • Leaving internal links pointed at old URLs
  • Applying a temporary 302 to a permanent move
  • Forgetting the old domain’s SSL certificate
  • Writing a broad regular expression that captures valid pages
  • Dropping valuable query parameters unintentionally
  • Redirecting image, script, or stylesheet requests unexpectedly
  • Deleting rules immediately after search results update
  • Confusing canonical tags with actual redirects

A canonical tag is a hint about the preferred version of similar content; it does not forward visitors. A 301 changes where the request goes. During a genuine permanent move, use the redirect and update canonical tags on the destination so the signals agree.

For broader technical checks that complement redirect testing, refer to [Internal Link: Technical SEO Audit Checklist].

Troubleshooting Redirects That Do Not Work

First, remove browser caching from the diagnosis. Test in a private window, use curl, or clear the cached redirect. Also check content delivery networks and hosting caches. A correct configuration change may not appear publicly until those layers have been purged or expired.

Next, confirm that the rule is being read. An Apache server may disallow .htaccess overrides, the file may be in the wrong directory, or a WordPress rule may run before yours. In Nginx, the edited configuration might not belong to the active virtual host.

Rule ordering often explains unexpected destinations. A broad domain or folder rule placed above a specific page rule can capture the request first. Move the specific rule earlier, or tighten the broader match. Review regular expressions carefully for unescaped periods, missing anchors, and optional slash behavior.

A 500 error generally indicates invalid configuration syntax or an unsupported directive. Restore the backup if the site is unavailable, then inspect the server’s error log. Correct one issue at a time and validate the configuration before applying it again.

For repeated redirects, trace every response rather than inspecting only the starting and ending pages. The chain will reveal which rule sends the request back to an earlier URL. Common conflicts involve HTTP-to-HTTPS enforcement, www normalization, CDN settings, and application-level redirects operating simultaneously.

Maintaining Redirects for Long-Term SEO

A redirect is not finished when it goes live. Update internal navigation, contextual links, XML sitemaps, canonical tags, hreflang references, structured data, and advertising destinations to use the final URL directly. Redirects are a safety net, not a substitute for maintaining clean links.

Keep permanent redirects active for as long as people, search engines, bookmarks, or external websites may request the old addresses. Domain migrations often justify retaining the old domain and its redirects indefinitely. Removing them too early can recreate broken links and discard referral traffic.

Periodically review the redirect list for chains, duplicate rules, inaccessible destinations, and legacy patterns that no longer match the current site. Do not remove an old rule merely because it receives little traffic during a short reporting period. Backlinks and saved bookmarks can remain useful for years.

Monitor important migrations through analytics and search-engine reporting tools. Compare visits, conversions, index coverage, and rankings before and after launch. Some fluctuation is normal while pages are recrawled, but widespread losses may indicate missing mappings, blocked destinations, content mismatches, or incorrect canonical signals.

Conclusion

A reliable permanent redirect has three parts: a clearly identified old URL, a relevant working destination, and a server response that returns the correct status without unnecessary steps. The implementation method varies—Apache uses directives or rewrite rules, Nginx uses server configuration, and content management systems often provide plugins or built-in controls—but the planning principles remain consistent.

When learning how to do a 301 redirect, focus as much on mapping and testing as on writing the rule itself. Back up the configuration, point each source directly to its final destination, and confirm a simple 301-to-200 response chain. Update internal links and technical signals so they reference the destination rather than depending on redirects permanently.

Avoid sending unrelated pages to the homepage, and use a 404 or 410 when no genuine replacement exists. For larger migrations, maintain a redirect spreadsheet and test the old URL set in bulk. A carefully maintained redirect preserves access for visitors, reduces broken links, and gives search engines clear information about where permanent content has moved.

Frequently Asked Questions

How long should a 301 redirect remain active?

Keep it active for at least a year, and preferably longer when old links, bookmarks, or search results may still generate visits. Redirects used for domain migrations are often worth maintaining indefinitely.

Does a 301 redirect pass SEO value?

A relevant, correctly configured 301 generally allows search engines to consolidate ranking signals with the destination. Results are strongest when the new page closely matches the old content and returns a successful response.

Can I redirect a deleted page to the homepage?

You can, but it is usually a poor choice unless the homepage genuinely satisfies the same intent. Use a close replacement when available; otherwise, a clear 404 or 410 response may be more appropriate.

What causes a too many redirects error?

The error usually means two or more rules form a loop. Trace the response chain and review application, server, CDN, HTTPS, hostname, and trailing-slash settings to locate the conflicting instructions.

Can a 301 redirect be changed later?

Yes, but browsers and intermediary caches may retain the original permanent redirect temporarily. Update the rule, purge relevant caches, and test with an uncached request tool to verify the new destination.

Submit a Comment

Your email address will not be published. Required fields are marked *