You've decided to redesign your website. You've planned the new structure, and you realize your beloved blog post about "The Best Coffee Grinders" needs a new, cleaner URL. It's moving from /blog/2018/best-coffee-grinders
to /guides/best-coffee-grinders
.
This is a common and sensible change. But it creates a huge problem: anyone who has bookmarked the old URL or clicked a link from another website will now hit a dead end a 404 Not Found
error. All the traffic, authority, and SEO "link juice" that the old page accumulated over years will vanish overnight.
This digital disaster is avoided by one of the most important and powerful instructions in the HTTP protocol: the 301 Moved Permanently
redirect.
While it might seem like just another line of code flying under the radar, 301 is extremely important for redirecting web traffic, preserving SEO, and ensuring smooth browsing experiences.
At its core, 301 means that a resource has been permanently moved to a new location. But as simple as that sounds, it comes with a lot of nuances especially if you’re working with web traffic, APIs, or search engine optimization.
A 301 redirect is the web's equivalent of setting up a forward with the post office. It's a permanent, one-to-one mapping from an old address to a new one. It tells browsers and search engines, "I'm not here anymore. I've moved to a new home, permanently. Please update your records and go there instead."
If you care about SEO, user experience, or maintaining a stable web, understanding the 301 redirect is non-negotiable.
In this blog post, we’ll talk about what a 301 status code is, why it’s used, how it affects your site or API, and best practices for implementation. If you’re working with APIs and want to test how your system handles redirects like 301, you don’t need to set up a server from scratch. You can use Apidog, a powerful all-in-one API design, testing, and documentation platform. With Apidog, you can simulate a 301 response, test client behavior, and document everything in one place. And yes, it’s free to download.
Now, let’s explore everything you need to know about HTTP status code 301 Moved Permanently.
The Problem: Link Rot and Lost Authority
The web is built on links. Over time, a valuable page accrues authority:
- Backlinks: Other websites link to it.
- Social Shares: People share it on social media.
- Bookmarks: Users save it for later.
- Search Engine Ranking: Google and others rank it highly for certain keywords.
If you change the URL without a redirect, you break every single one of these connections. This is known as "link rot," and it's a major source of frustration and lost value on the internet. The 301 redirect is the definitive solution to this problem.
What Is HTTP Status Code 301 Moved Permanently?
The 301 Moved Permanently status code is part of the HTTP 3xx class of status codes, which deal with redirection.
When a client (like a browser or API consumer) requests a resource, and the server responds with 301
, it’s saying:
“This resource no longer lives here. It’s been permanently moved to a new URL.”
Along with the 301 response, the server typically includes a Location header, which tells the client where to go next. When a server responds with a 301 status code, it’s telling the client: “The resource you’re looking for isn’t here anymore. It’s now at a new URL, and you should update your links or bookmarks accordingly.”
Here’s a simple example:
HTTP/1.1 301 Moved Permanently
Location: <https://example.com/new-page>
When the client sees this, it will automatically go to the new URL. This is important because it indicates a permanent change unlike temporary redirects (like status code 302 Found) where the original URL might still be valid later.
Why Is 301 Moved Permanently Important?
The 301 status code plays a crucial role because it:
- Improves User Experience: Users clicking old links get seamlessly redirected to the right place without hitting dead ends.
- Preserves SEO Value: Search engines transfer the ranking signals, backlinks, and authority of the old URL to the new one.
- Ensures Consistency: Visitors and bots get a clear message that the content has moved, avoiding duplicate content and confusion.
- Supports Website Changes: When redesigning sites, restructuring URLs, or migrating content, 301 redirects help maintain traffic flow.
Without proper use of 301 redirects, you risk losing search engine rankings and frustrating users with broken links.
Key Importance of 301:
- Preserves user experience → Visitors don’t hit broken links.
- Passes SEO value → Search engines transfer ranking power from the old URL to the new one.
- Supports API stability → Clients don’t break when resources move.
How It Works: The Browser's Journey
Let's follow what happens when you encounter a 301 redirect.
- You Click a Link: You click an old link:
https://old-site.com/classic-page
. - The Request: Your browser sends a request to
old-site.com
's server. - The 301 Response: The server responds with
301 Moved Permanently
and aLocation: <https://new-site.com/modern-page
> header. - The Automatic Redirect: Your browser sees the
301
status and theLocation
header. It immediately and automatically makes a new request to the URL in theLocation
header. This happens without you ever seeing it. - The Final Destination: The server at
new-site.com
responds to the new request with a200 OK
and the content of the modern page. - The Browser Updates the Address Bar: Your browser's address bar updates to show the new URL:
https://new-site.com/modern-page
.
From the user's perspective, they clicked a link and ended up on the right page. The complex redirect dance happened seamlessly in the background. This redirection is typically seamless to users and search engines. Think of it like moving houses: 301 is the “forwarding address” that ensures your mail (or in this case, requests) get delivered correctly.
When Should You Use 301 Moved Permanently?
Using 301 redirects properly can keep your site healthy and your URLs tidy. Common cases include:
- Website migrations: When moving your site to a new domain.
- URL structure changes: Changing paths or rewriting URLs for better readability.
- Canonical URLs: Consolidating different URLs that serve the same content (e.g., with and without www).
- Fixing broken links: Redirecting outdated links to current resources.
- Content repurposing: When content is merged or relocated permanently.
The SEO Superpower: Preserving "Link Juice"
This is the most critical aspect of a 301 redirect. Search engines like Google understand the 301
code semantically. When they encounter it, they do two things:
- They Index the New URL: They start crawling and indexing the content at the new location.
- They Transfer Link Equity: They transfer the vast majority of the ranking power, authority, and "link juice" from the old URL to the new one.
This means your new page can essentially inherit the search engine ranking of the old page. Without a 301 redirect, that equity is lost.
301 vs. Other Redirects: Knowing the Right Tool for the Job
Not all redirects are created equal. Using the wrong one can cause problems.
301 Moved Permanently
: Permanent. Use this when you know the move is... permanent. For changing domains, restructuring your site's URL schema, or moving from HTTP to HTTPS. It tells search engines to update their index and transfer equity.302 Found
: Temporary. Use this for short-lived things, like A/B testing a new page layout or during brief maintenance. Search engines will keep the original URL in their index and will not transfer link equity. Using a 302 for a permanent move is a common SEO mistake.307 Temporary Redirect
: A modern, stricter version of302
that guarantees the browser will not change the HTTP method (e.g., a POST will remain a POST).308 Permanent Redirect
: A modern, stricter version of301
that also guarantees the HTTP method will not change.
For most common use cases (changing a page's URL), 301
is the perfect and correct choice.
SEO Considerations for 301 Redirects
One of the most talked-about reasons to use 301 redirects is SEO. Here’s what you need to know:
- Search engines treat 301 redirects as a signal that the page permanently moved.
- Most link equity (ranking power) transfers through 301 redirects, preserving your SEO investments.
- It can take some time for search engines to process the redirect and update indexes.
- Avoid redirect chains (multiple sequential redirects) as they dilute link equity and decrease performance.
- Clear and permanent 301s help avoid duplicate content penalties.
Examples of 301 in Action
Example 1: Website Migration
GET /old-page HTTP/1.1
Host: www.example.com
Response:
HTTP/1.1 301 Moved Permanently
Location: <https://www.example.com/new-page>
Example 2: API Versioning
GET /api/v1/users HTTP/1.1
Response:
HTTP/1.1 301 Moved Permanently
Location: /api/v2/users
Example 3: Domain Rebranding
GET /about-us HTTP/1.1
Host: oldbrand.com
Response:
HTTP/1.1 301 Moved Permanently
Location: <https://newbrand.com/about-us>
How to Implement a 301 Redirect
There are two main ways to set up a 301 redirect, depending on your control over the server.
1. Server-Side Configuration (The Best Practice)
This is done by configuring your web server (like Apache or Nginx) or your application framework. It's fast, efficient, and happens at the protocol level.
Apache (via .htaccess file):
Redirect 301 /old-page.html <https://www.new-site.com/new-page.html>
or more powerfully with mod_rewrite
:
apache
RewriteEngine On
RewriteRule ^old-blog/(.*)$ /new-blog/$1 [R=301,L]
Nginx (in server block config):
server {
...
location /old-page.html {
return 301 <https://www.new-site.com/new-page.html>;
}
}
2. Application-Level (Less Efficient)
This is done within your application code (e.g., PHP, Node.js, Python). It's more flexible but slower because it requires booting up your application to handle the request.
PHP:
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: <https://www.new-site.com/new-page.html>");
exit();
?>
Node.js (Express):
javascript
app.get('/old-page', (req, res) => {
res.redirect(301, '<https://www.new-site.com/new-page>');
});
How Apidog Helps You Work With 301 Redirects

While browsers handle redirects automatically, testing and verifying redirect behavior is key in API development. Getting redirects wrong can create infinite loops or break your site. Testing is crucial. This is where Apidog becomes an essential tool.
With Apidog, you can:
- Trace Redirects: Send a request to an old URL and watch as Apidog automatically follows the redirect chain, showing you each step (301 -> 200) and the final destination.
- Verify the Status Code: Ensure the server is sending a
301
and not a302
. This is critical for SEO. - Check the Location Header: Validate that the
Location
header contains the correct, absolute URL. - Test in Bulk: If you've changed many URLs, you can use Apidog to create a collection of tests that check all your old URLs to ensure they correctly 301 redirect to the new ones.
- Avoid the Browser Cache: Browsers aggressively cache 301 redirects. This makes testing a nightmare because a mistaken 301 can be hard to undo. Apidog doesn't have this problem, allowing for clean, repeatable testing.
With this, you can simulate real-world scenarios like an API migrating to a new version without needing to deploy backend changes. Downloading Apidog for free gives you this powerful testing capability, so no redirects surprise you during deployment!
How APIs Handle 301 Responses
While websites handle 301
pretty seamlessly, APIs require more thought.
Clients must handle redirects explicitly:
- Some HTTP clients automatically follow redirects.
- Others require manual handling.
Here’s how a typical API client sees it:
HTTP/1.1 301 Moved Permanently
Location: /api/v2/resource
If you don’t configure your API client properly, it might just stop at the 301 instead of following through.
Common Use Cases for 301 Redirects
- Domain name changes →
oldsite.com
→newsite.com
. - Switching from HTTP to HTTPS → Redirecting all
http://
requests tohttps://
. - Merging websites → Combining multiple microsites into one domain.
- API version upgrades → Redirecting clients from
v1
tov2
. - SEO cleanup → Fixing duplicate content by consolidating URLs.
Common Pitfalls and Best Practices for Developers and SEO Teams
- Avoid Redirect Chains: Try to point the old URL directly to the final destination (A -> C) instead of chaining (A -> B -> C). Each redirect adds latency. Ideally, redirect directly.
- Use Absolute URLs: Always use a full, absolute URL (https://...) in the
Location
header. Combine your HTTPS migration with 301 redirects. - Update Internal Links: Don't rely on redirects for your own site's navigation. Update your internal links to point directly to the new URLs. Redirects are for users and search engines coming from the outside.
- Be Certain: Remember,
301
means permanent. Search engines and browsers will cache this aggressively. Don't use it for testing. - Check Your Work: After implementing, use tools like Apidog, Screaming Frog SEO Spider, or browser dev tools to verify the redirect is working correctly and returning a
301
status. - Document redirects: If working in APIs, use Apidog to make redirect behavior clear.
- Test everything: Run through different clients, devices, and environments.
Common Mistakes to Avoid With 301 Redirects
- Using 302 instead of 301 for permanent moves: 302 is for temporary redirects and doesn’t transfer SEO benefits.
- Creating redirect chains: Multiple redirects slow down requests and may cause SEO issues.
- Redirecting many URLs to a single page indiscriminately: Can look like soft 404s and hurt rankings.
- Forgetting to update internal links: Redirects help but updating links directly is better.
- Ignoring HTTPS migration: Ensure 301s properly handle http to https redirects for security and SEO.
Redirect vs Rewrite: What’s the Difference?
It's worth clarifying that a redirect (like 301) tells the client to visit a new URL. A rewrite happens on the server side and internally maps one URL to another without telling the client. Redirects involve client interaction and update the browser address bar, whereas rewrites are transparent to clients.
Monitoring and Managing Redirects
Keep your redirects efficient by:
- Regularly reviewing redirect maps.
- Eliminating unnecessary or outdated redirects.
- Using tools like Apidog to test redirect responses.
- Keeping load times low by avoiding lengthy redirect chains.
Conclusion: Why 301 Moved Permanently Matters to Every Developer
The HTTP 301 Moved Permanently
status code is more than just a technical instruction; it's a fundamental pillar of a stable, user-friendly, and SEO-friendly web. It allows the internet to evolve and change without breaking the countless connections that give it value.
It empowers developers and site owners to improve their websites, safe in the knowledge that they won't sever their hard-earned connections to their audience and their search engine rankings.
Whether you’re migrating a website, cleaning up URLs, or managing an API, understanding and using 301 redirects properly can save you headaches and preserve your traffic.
If you’re an API developer or website manager, learning to use 301 correctly can save you headaches, protect your SEO rankings, and provide a smooth user experience.
And remember when it comes time to testing 301 responses or mocking redirect scenarios, Apidog is your best friend. It lets you design, test, document APIs (including edge cases like redirects) in one place and troubleshoot HTTP status codes like 301 empowering you to build better web experiences. Download it today for free and make your API development journey easier.