4

The Ultimate Guide to Redirects: URL Redirections Explained

 1 year ago
source link: https://www.semrush.com/blog/redirects/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

What Are Redirects?

Redirects send users from one URL to another. 

The first URL is the one the user clicked, typed in, or otherwise requested. The second is the new destination URL. 

Redirections work pretty much the same way for search engines. They send search engines from one particular URL to another.

Website owners often set up redirects for pages that are broken, contain duplicated content, or were moved to new URLs.

This way, users and search engines access the most relevant or current page.

That’s good for the user experience. And it can prevent SEO problems.

Which can help your website rank higher.

Let’s get started by covering why redirects are important.

Why Are Redirects Important?

Redirects are important because they:

  • Forward traffic from one URL to another when the old URL no longer exists
  • Forward authority when backlinks point to a page that has been moved
  • Improve the overall user experience by ensuring visitors don’t land on broken or duplicated pages

If you forget to implement redirects, you can lose search engine rankings and end up with unhappy users. 

Here’s an example: 

Say you move or delete a page but don’t put a redirect in place. Users will receive a 404 error response from the server.

Which creates a poor user experience.

Typically, 404 pages display an error message. Like this:

Upflex 404 page example

That’s not good for the user experience. A 404 might cause visitors to leave your site.

Proper redirects prevent 404 errors. And that helps users find the pages they’re looking for. 

What if you have backlinks pointing to a page that has been moved (and is now triggering 404 errors)? 

Big problem: 

You won’t gain any authority from those backlinks. That’s confirmed by Google Search Advocate John Mueller:

The link goes nowhere, so we drop it. If you recommend something that doesn't exist anymore, it's really a useful recommendation, right?

— johnmu 🐀 (@JohnMu) November 18, 2021

When to Use Redirects

Here’s a list of common reasons for redirections:

  • You move the URL of a webpage (from URL A to URL B)
  • You delete a page
  • You add category tags or parent pages that affect URLs
  • You move your website to a new domain
  • You’re performing maintenance on a webpage
  • You merge two or more duplicate webpages
  • You migrate your site from HTTP to HTTPS

You can apply a redirect to a single URL. Or to a group of URLs. You can also redirect an entire domain to another domain name.

You may need to use a different type of redirect depending on your situation. Let’s cover the most common ones and when to use them.

Types of Redirects

There are two main categories of redirects: permanent and temporary

Users won’t be able to tell the difference between the two. But they are important for search engines. 

Here’s why:

Permanent redirects are for when you don’t expect to display the old page again. Like if you delete a page. Or if you combine duplicate pages. 

They tell search engines it’s OK to remove the old URL from search results and start displaying the new one.

Then you have temporary redirects. They’re for when you need to redirect a page for a short time. 

For example: 

Say you’re performing website maintenance. You could temporarily redirect users to a message telling them to check back after maintenance is complete. 

With a temporary redirect, Google will usually keep the old URL in its index for longer than it would for a permanent redirect. 

This is because a temporary redirect signals that the old URL will be the primary one again at some point in the future.

Because redirects are signals to Google, it’s important to choose the right one to communicate what you want to do with a particular URL. 

Now, we’ll cover HTTP redirects (which you’ll likely use most of the time), meta refresh redirects, and JavaScript redirects. Plus when to use them.

HTTP Redirects

Here’s how an HTTP redirect works: 

The user’s browser requests the old (redirected) URL. The server automatically displays the webpage for the new URL (the redirect target).  

From the user’s point of view, HTTP redirects are completely seamless.

In technical terms, these are called server-side redirects. Because your web server (where your website is hosted) takes care of it before your website even loads.

It does that by responding with a 3xx HTTP code when it receives the request for the redirected URL.

Those 3xx codes are like instructions for your browser. They indicate that the requested URL has been redirected. And where to find the new webpage (the redirect target).

Here’s a simple list of the most common types of 3xx codes (and what they mean when a server sends them). We’ll get into the specifics of each one below:

  • 301: Moved permanently 
  • 302: Redirected temporarily
  • 303: Redirected temporarily
  • 307: Redirected temporarily
  • 308: Redirected permanently

For more details on each redirect type, read on:

301 Redirects (Moved Permanently)

301 redirects signal to Google that the move is permanent. 

They’re also considered the best way to pass link equity if you need to redirect a page. 

That’s because they pass some page authority from the old URL to the new URL.

But keep in mind that page authority diminishes with each 301. So only use them when necessary.

Let’s get into a real-life example of how 301s work.

Say your site has two pages about dog toys. There’s no need for two pages about the same topic. And one page is outdated.

301 redirect example page

In this case, it would be best to delete the older, outdated page and 301 redirect its URL to the new page’s URL.

To learn more, read our guide to 301 redirects.

302 Redirects (Found & Moved Temporarily)

Another common redirect is a 302. A 302 redirect tells Google that a redirect is temporary. 

While they are temporary, 302s can still pass page authority of the old page (though it happens over time).

Use a 302 redirect when:

  • You temporarily move your page to a new URL
  • A page is under maintenance
  • When you want to A/B test new website design or copy

Not sure when to use a 302 instead of a 301?

In general, only use a 302 if you plan to bring back the original URL back at some point (or set up a new one).

Other HTTP Redirects

As far as server-side redirects go, you’ll only need to use a 301 or 302 in most cases. 

But there are other types of HTTP redirects. These are much more rare. But they can still be good to know in certain situations:

  • 303 redirect (see other): Redirect that sends users to another relevant page when the old one is not available (most often when users have already submitted a form and cannot resubmit) 
  • 307 redirect (moved temporarily): Similar to a 302 redirect, but directs server requests for the webpage differently (302s are generally considered to be better for SEO)
  • 308 redirect (moved permanently): Indicates a permanent move and is treated the same as a 301 (though it can make your reporting confusing if you switch between the two at random)

Meta Refresh Redirects

Meta refreshes happen at the page level (client-side) rather than the server level. That means they happen in your browser rather than on a server. Unlike HTTP redirects.

Here’s the thing:

If you have to do a redirect, HTTP redirects are better than meta refreshes for SEO. 

Meta refreshes can confuse Google and website visitors. They’re slower (hurting user experience). And they might lead to Google indexing the wrong page.

But Google only recommends meta refresh redirects if you can’t use a server-side redirect. This is because they’re slower and don’t pass as much link equity.

There are two types of meta refresh redirects: instant and delayed. 

Instant meta refresh redirects trigger as soon as a page is loaded in a browser. Google interprets these as permanent redirects.

They look like this:

<meta http-equiv="refresh" content="0; url=https://www.semrush.com/">

Delayed meta refresh redirects trigger after a number of seconds you choose. Google interprets these as temporary redirects.

Here’s an example that’s triggered after five seconds:

<meta http-equiv="refresh" content="5; url=https://www.semrush.com/">

JavaScript Redirects

JavaScript redirects also happen on the client side rather than the server side.

And like meta refresh redirects, they aren’t recommended for SEO. This is because Google may not index your pages correctly when redirecting using JavaScript.

And that could hurt your website’s rankings in search results.

Tests show that Google treats JavaScript redirects similarly to 301s. But it’s not guaranteed—so you may be pushing your luck with page authority if you go with this type of redirect.

Here’s an example of a JavaScript redirect in your HTML code:

window.location.replace("https://example.com");

You can learn more in our guide to JavaScript redirects.

How to Implement Redirects

There are three main ways to set up HTTP redirects: 

  • Through plugins
  • Through your CMS (content management system)
  • Through an .htaccess file

Use WordPress Plugins 

If you use WordPress, you can set up redirects with plugins.

We’ll use Yoast for this example because it’s one of the more common SEO plugins. But there are many similar 100% free options (like Redirection).

To start the process with Yoast, first download the plugin from the WordPress store. (Or download the plugin of your choice.)

After installing, head to the “Plugin” page on the WordPress and click Activate.” 

Activate Yoast SEO plugin

The plugin is now active.

Next, select Redirects under the Yoast menu of the left-hand toolbar (the “SEO” with a “Y” next to it):

Yoast SEO in WordPress toolbar

Next, choose what type of redirect to set up.

choose redirect type

Enter the slug (the part of the URL after “.com”) of the old URL you wish to redirect and the new URL you wish to redirect to. 

Ensure that the slug is spelled correctly. Otherwise, the redirect won’t work properly.

Add redirect in Yoast

Click Add Redirect and your redirect will be live.

You’ll find a full list of live redirects below the Add Redirect button.

Live redirects

To learn more, read our in-depth guide to setting up redirects on WordPress.

Use Wix

If you use Wix, you can set up redirects directly in your CMS.

Scroll down to the bottom of your website control panel. Click on SEO Tools under “Marketing & SEO.”

Wix SEO tools

Click URL Redirect Manager at the bottom left corner of the tools list.

Then, hit the New Redirect button at the top right corner of your screen.

A pop-up will appear. Here, you can select your type of redirect. And add the old URL you wish to redirect from.

Finish by clicking Save or Save & Add Another.”

Use an .htaccess File

You can also perform redirects manually.

Warning: This option is only for experts. If you make a mistake, it can cause big problems for your website.

You can set up redirects with a file called .htaccess. It’s in plain text and looks like this:

Apache servers use the .htaccess file. (But these can be found on other types of servers, too). 

Start by locating the RewriteEngine (which can be found in the mod_rewrite module in Apache).

This module should already be in Apache by default. But if it’s not being loaded, you can add it using this code:

<IfModule mod_rewrite.c>
RewriteEngine On
</IfModule>

Now, we’ll add our rules directly below “RewriteEngine On.”

Redirect a Single URL

To redirect one URL, use the code below. Specify the type of redirect and replace /oldpage/ and /newpage/ with the actual slugs of your pages.

Redirect 301 /oldpage/ https://www.example.com/newpage/

Redirect a Single Folder

To redirect a folder, use the following code and replace “folder” with the folder you’d like to redirect and “location” with where you’d like to redirect the folder.

RewriteRule ^folder/(.*)$ /location/$1 [R=301,NC,L]

Redirect to Another Domain

To redirect to a new domain, add the following code:

RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

Redirect Non-www to www

If users (or search engines) try to reach URLs without the “www” subdomain, you can redirect them to the URL that does include it.

There’s not a huge practical difference between the two. But Google views www and non-www versions of the same URL as different entities. 

So choosing one “correct” subdomain helps Google understand which one is “official.”

Add this code to redirect a non-www URL to a www URL:

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

Redirect www to Non-www

This is essentially the opposite of the above. If you don’t want users to access the “www” subdomain, you can add this code:

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

Non-www URLs can be useful for direct traffic, as people usually enter in URLs without the “www.” However, keep in mind that you have less control over cookies with the non-www subdomain.

Redirect HTTP to HTTPS

If you’re looking to redirect HTTP pages to HTTPS, here’s the code you’ll need:

RewriteCond %{https} off
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]

Keep in mind that you’ll need to purchase an SSL certificate before redirecting to HTTPS, though. Learn more in our HTTP to HTTPs redirect guide.

5 Redirect Best Practices

Now that we've covered how to redirect pages, let's cover some of the most important best practices to follow.

1. Always Redirect to Close Match Content

When you set up a redirect, make sure that the new page’s content is a close match to the old page’s.

For example, redirecting an expired specials page to your main specials page instead of your homepage makes a lot more sense.

If you redirect an old URL to a URL that isn’t relevant, search engines may not pass on the authority of the old page. This can result in a soft 404.

A soft 404 happens when the server sends a “200 OK” HTTP status, but Google thinks the page should 404. (200 status codes mean the request was successful according to the server.)

This issue can happen if your page has no content on it (like an empty product category or blog category page), if your page seems unrelated to the redirected page, or if the page displays a 404 message (but still sends to 200 HTTP status).

Technically, a soft 404 isn’t a status code. It’s more of a label Google uses to make sense of the page.

Google essentially skips over true 404 pages. This doesn’t happen with soft 404 errors, so it’s best to avoid them and fix any existing errors.

You can find soft 404s with Google Search Console.

Head over to the Coverage tab under “Index.”

Search Console marks soft 404s as errors. It will give you a list of URLs that appear to be soft 404s in the “Errors” section underneath the graph.

Once you find the soft 404 errors, it’s time to fix them. 

For any soft 404 related to redirects, update the redirect so that it points to the most relevant page available.

2. Avoid Redirect Chains & Loops

A redirect chain is when more than one URL redirect exists between the original URL and the final URL.

Let’s say that a page’s URL was previously www.yoursite.com/about-the-company/ (URL A) before it was redirected to www.yoursite.com/about-us/ (URL B). 

If you later redirect the newer URL to www.yoursite.com/about/ (URL C), that would create a redirect chain.

Because now the first URL redirects to the second URL. And the second URL redirects to the third URL.

Like this:

redirect-chain

Google can follow up to 10 redirect “hops” without issues. But be careful of making things too complex.

Redirect chains that are too long can delay crawling, cause losses in link equity, and increase page load time. Which can hurt your SEO and frustrate users.

To fix the issue, redirect straight from URL A to URL C without stopping at URL B.

This is what a corrected redirect chain looks like:

A redirect loop occurs when a URL redirects to another URL. And that second URL redirects back to the original URL. This creates an infinite circle of redirects.

Like this:

This redirection is broken and won’t actually forward visitors or search engines to the destination. 

Fix redirect loops by choosing the “correct” page and ensuring the other page redirects to it. Then delete the other redirect causing the loop.

You can use our Site Audit tool to check for redirect chains and loops.

First, set up a project or click on the existing one that you want to check on.

Then, go into the Issues tab and filter for “redirect chain” by typing it into the search bar.

Click on the # redirect chains and loops.” You’ll get a full report of pages with redirect chain or loop errors.

The report contains a list of pages, their redirect type, and the number of redirects.

List of issues with redirect issues in Site Audit

Log into your CMS and fix each one. 

To sum it up:

  • Fix redirect chains by redirecting the old URL directly to the new URL. Delete any unnecessary redirects in-between. 
  • Fix redirect loops by choosing the “correct” page. Redirect to the correct page from the other page. Then delete any other unnecessary redirects causing the loop.

Fix Redirect Chains and Loops

with the Site Audit Tool

ADS illustration

3. Avoid Linking to Pages with Redirects

Say you redirect an old page to a new page. You might have other pages on your site that still link to your old page.

If so, users will be sent to your old link. And then redirected to the new URL. 

Users probably won’t notice this. But that extra redirect can contribute to a redirect chain over time if you don’t remember to maintain it. 

Here’s what the issue looks like:

So, it’s best to change old internal links to your new page’s URL. Which looks like this:

But how do you find links on your website that point to redirects?

It’s simple:

Head to the Crawled Pages tab of the Site Audit tool.

Then, add your old (redirected) URL into the “Filter by Page URL” space.

After you hit Enter,” you’ll see a report for your specified URL. Click on it.

Crawled Pages report for one URL

You’ll find a list of internal links pointing to your old URL under the “Incoming Internal Links” section.

Now, all you have to do is swap the old link for the new link (the redirect target). 

Go to each page in the list and manually change the link. This will fix the error.

4. Redirect to Avoid Duplicate Content

It’s not uncommon to find that a site exists on more than one subdomain (non-www and www, HTTP and HTTPS, etc.). 

For example, http://example.com and https://example.com point to the same domain. 

Search engines view them as separate sites, which isn’t a bad thing by default. However—this can cause duplicate content issues if you aren’t careful.

Essentially, you could split traffic and compete with yourself if Google isn’t sure which version of your site to direct users to.

You can easily resolve this issue by 301 redirecting all variants of a page to a single URL. This will direct Google to your preferred page (the redirect target).

Use redirects to prevent duplicate content in the following instances:

  • Non-www and www URLs
  • HTTP and HTTPS URLs
  • Trailing-slash (/) and non-trailing-slash URLs
  • Capitalized and lower-case URLs

You can find duplicate content on your site in the “Issues” tab of our Site Audit tool. Filter by “duplicate” to get a list of relevant errors.

Click on the # pages have duplicate content issues” error to get a full report.

The tool will give you a list of pages that you may need to redirect. Along with how many duplicate pages exist.

Results of pages with duplicate content issues in Site Audit

Click on the dropdown arrow on the right side of each listing to see the duplicate pages.

And redirect each duplicate page, as necessary.

5. Fix 404s to Regain Lost Link Authority

Google ignores backlinks that point to a 404 page. And that’s a problem because backlinks are an incredibly important ranking factor.

In other words, you’re not getting any credit from Google for those backlinks pointing to 404 pages.

Here’s a quick fix:

Use our Backlink Analytics tool to uncover 404 pages that have links pointing to them. 

Head to the Indexed Pages tab in your completed report. Tick the box beside “Broken Pages.”

Broken Pages in Backlink Analytics

You’ll get a list of missing URLs that have links pointing to them.

Errors in Backlink Analytics

Reclaim some of that lost authority by 301 redirecting those pages to a close match page.

Uncover 404 Pages with Backlinks

with the Backlink Analytics Tool

ADS illustration

Redirect FAQs

Do Redirects Pass Page Authority?

Yes, 301 redirects will pass authority from the old page to the new page. If there is a close match between each page’s content.

But keep in mind that redirects may not necessarily pass 100% of the original page’s authority.

If you have a legitimate reason to redirect a page, though, it is best practice to implement the redirect.

Are Redirects Bad for SEO?

In short, no. But it’s a bit more complicated than that.

The best-case scenario is to avoid needing redirects entirely. That way, your pages won’t lose any authority.

But you’ll likely need to redirect some pages at some point in time. In this case, implementing redirects (correctly) is the best way to help protect your current rankings. 

And avoid losing page authority.

If you move or remove a webpage and don’t redirect the old URL, users and Google will get a 404 when they land on the old URL. 

They’ll be lost. And might bounce from the page.

While 404s generally aren’t thought to be a Google ranking factor, they can be problematic if you point internal links to a page that no longer exists.

In this case, it’s best to redirect to a relevant page rather than let users and search engines fend for themselves.

How Long Should You Keep Redirects in Place?

According to Google’s Gary Illyes, you should keep permanent redirects in place for at least a year. 

(Ideally, indefinitely. That’s best for user experience.)

hands up if you asked us recently for how long you should keep redirects in place!
i have a concrete answer now: at least 1 year.
(but try keeping them indefinitely if you can for your users).

— Gary 鯨理/경리 Illyes (@methode) July 21, 2021

After this time frame, Google says it is able to transfer all ranking signals to the new URL. 

How Do I Test Redirects?

Luckily, testing a redirect is simple.

All you need to do is copy the old URL and paste it in your browser. If it directs you to the new URL after you hit enter, then congratulations! Your redirect works.

If not, see if you made any typos when setting up your redirect.

To check for more complex redirect issues, you can use the Site Audit tool.

Find and Fix Redirect Issues

with the Site Audit Tool

ADS illustration

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK