URL Redirects in SEO: A Complete Guide

1_URL-redirect

Redirects are an important aspect of SEO as they affect how search engines, like Google, crawl and index websites. In the SEO world, it’s an undeniable fact that redirects and SEO can have serious ramifications.

When used correctly, redirects in SEO can improve a website’s search engine rankings and user experience.

However, it is important to use the appropriate type of redirect and to ensure that they are properly implemented to avoid negative consequences for search engines and users.

This article provides a thorough overview of redirects and their proper use for technical SEO.

Redirects in SEO?

URL redirects are a way to guide users and search engines to the correct webpage when a specific URL is entered or clicked.

These redirects are implemented through code and can be temporary (302, 303, 307, 308) or permanent (301).

When a redirect is triggered, the user or search engine is directed to a different page than the original URL.

This helps to ensure that users and search engines can find the correct webpage, even if the URL has changed or been moved.

When Should You Use Redirects in SEO?

There are several instances when you should use a redirect.

The main being,

  1. When an individual page or entire domain has been moved (URL changed)
  2. To shorten the URL (Good for SEO)
  3. Site migration

From an SEO perspective, URL redirects are needed

  1. As they forward the page authority of any links pointing to a page that has moved or been deleted.
  2. To avoid 404 page not found errors

Redirects can be applied to a group of URLs or to an entire domain, but it is often more effective to set them on an individual basis to avoid any potential issues.

If you use regular expressions (RegEX) for group redirects, it is important to be careful with your logic as mistakes can lead to unexpected results.

Redirect Types

There are 3 Types of Redirects:

3_Redirect-types.webp

1. Meta Refresh Redirects

Meta refresh redirects are a type of redirect that is implemented through the use of a meta tag in the HTML of a webpage.

While they can be useful in certain situations, they are generally not recommended for SEO purposes because they are often seen as slower and less reliable than other types of redirects.

There are two types of meta refresh redirects: delayed, which is seen as a temporary redirect, and instant, which is seen as a permanent redirect. 

It is important to use the appropriate type of redirect based on the specific situation and to ensure that redirects are properly implemented to avoid negative consequences for search engines and users.

2. Javascript Redirects

Javascript redirects are implemented through the use of Javascript code and are set on the client side’s webpage. 

While they can be useful in certain situations, they can also cause SEO issues because Google has indicated a preference for server-side redirects that are implemented using HTTP.

It is important to consider the impact on SEO when choosing a type of redirect and to ensure that redirects are properly implemented to avoid negative consequences for search engines and users.

3. HTTP Redirects 

HTTP redirects are set on the server side and are generally the most recommended approach for SEO purposes. We will delve into more detail about these types of redirects in the following sections.

What is a HTTP Response Status Code?

When a user agent, such as GoogleBot, tries to access a webpage, it sends a request to the website server. The server then sends a response, which is known as an HTTP response status code.

This code provides information about the status of the request for the URL. For example, a response code of 200 indicates that the request for the URL was successful.

The process of a user agent, accessing and crawling a website involves a series of requests and responses between the user agent and the server.

HTTP Redirects

An HTTP redirect is a server response to a request for a URL. If the URL has been moved to a different location, the server will send a response code, such as a 301 or 302, indicating that the URL request is being redirected to a new location.

These response codes, which belong to the 3xx series, provide information that the user agent can use to take certain actions, such as saving a cache of the new URL so that future requests for the old URL will automatically go to the new URL.

In short, an HTTP redirect is not just a sign pointing to a new location, but also includes additional information that can be used by the user agent.

3XX Series Status Code

There are seven different types of redirects that can be used in web development, beyond the commonly known 301 and 302 response codes. These additional redirects are designated as 3xx response status codes.

2_status-code.webp

When implementing redirects in web development, it is important to be mindful of the different types of redirects that are available and to consider the compatibility of these redirects with the intended user agents.

While the 301 and 302 redirects are widely supported, some of the other 3xx redirect codes may not be as widely recognized or supported.

It is advisable to verify that the user agent you are targeting is able to interpret any redirect codes you plan to use beyond the 301 and 302 status codes.

What is 301 Redirect in SEO and Why is it Important?

301: Moved Permanently

The 301 redirect is a type of status code that is used to inform user agents (such as web browsers) that a requested URL has been permanently moved to a new location.

This redirect instructs the user agent to use the new URL for future requests, instead of the original one.

It is important to note that the 301 redirect carries additional information beyond just the change of URL location, and it is often used in conjunction with other data or instructions.

The 301 Status code also for: –

  • Future requests for the URL should be made with the new URL.
  • Whosoever is making the request should update their links to the new URL.
  • Subsequent requests can be changed from GET to POST.

In the context of search engine optimization (SEO), it is important to use the 301 redirects correctly when permanently moving a page to a new URL.

When search engines encounter a 301 redirect, they will transfer the ranking and link equity of the old page to the new page.

If a 301 redirect is used incorrectly, such as for a temporary move or change, it can cause confusion for search engines and potentially harm the search engine rankings of the pages involved.

Therefore, it is essential to carefully consider the use of a 301 redirect and ensure that it is only used for permanent URL changes.

The 301 status code should only be used for permanent URL changes, as indicated by the “Moved Permanently” description of the status code.

If the change being made is temporary, a different status code such as 302 (Found) or 307 (Temporary Redirect) should be used instead.

It’s also important to note that if a temporary change is made using a 301 redirect and then reversed to return to the original URL, the original URL may take time to regain its rankings and may not perform as well as it did before the temporary redirect was put in place.

To avoid these negative consequences, it is important to use the 301 status code only for permanent URL changes.

302: Found

The 302 status code, also known as “Found” or “Moved Temporarily,” indicates that a requested URL has been temporarily moved to a different location.

This status code is often used when a URL change is intended to be temporary and the original URL is expected to be used again in the future.

307: Temporary Redirect

The 307 status code, also known as “Temporary Redirect,” indicates that a requested URL has been temporarily moved to a different location.

Like the 302 status code, the 307 status code is used for temporary URL changes, and the original URL is expected to be used again in the future.

However, the main difference between the 307 status code and the 302 status code is that the 307 redirect requires the user agent (such as a web browser) to request the new temporary URL using the same HTTP request method as the original request.

For example, if the original request was made using the GET method, the user agent must use the GET method to request the new temporary URL and cannot use the POST method.

This requirement helps to ensure the integrity of the original request and any associated data.

302 vs 307

There are various ways to implement redirects on a web server, depending on the software being used. On an Apache server, redirects can be set up using the .htaccess file, while on an Nginx server, they can be configured in the example.conf file.

If you are using a content management system such as WordPress, you may also have the option to use plugins to manage redirects.

Regardless of the method used, the syntax for writing redirect rules is generally the same. Here is an example of how a redirect might be set up on an Apache server:

				
					Redirect 301 /old-url.html /new-url.html

				
			

This example redirects any requests for the “old-url.html” to the “new-url.html” using the 301 status code, which indicates that the redirect is permanent. The specific commands and syntax used may differ depending on the server software and configuration method being used.

On Nginx servers, it will look like this:

				
					rewrite ^/oldfolder/ /newfolder/ permanent;
				
			

The commands used to tell the server’s status code of redirect and the action command differ.
For instance:

  1. Servers status code of redirect: “301″ vs. “permanent.”
  2. Action command: “RedirectMatch” vs. “rewrite.”

To set up redirects on an Apache server, it is important to ensure that the mod_rewrite and mod_alias modules are enabled.

These modules are responsible for handling redirects and must be enabled in order for redirects to work correctly. The syntax for writing redirect rules is generally the same regardless of the server software or configuration method being used.

In this example, the “^/oldfolder/” and “/newfolder/” values represent the old and new locations of the URL being redirected, respectively. To set up redirects using an .htaccess file on an Apache server, you will need to include the following lines at the top of the file:

				
					Options+FollowSymlinks
				
			

These lines enable the necessary modules and allow you to use the RewriteEngine directive to manage redirects. You can then place your redirect rules below these lines in the .htaccess file.

It’s also important to ensure that the .htaccess file has the appropriate permissions to be read and executed by the web server.

How to Create a URL for a Single URL

One common use case for redirects is when a page or URL has been deleted or moved to a new location. In this scenario, you can use a redirect to direct users and search engines from the old URL to the new URL.

Here are two examples of redirect rules that could be used in this case:

				
					RewriteRule ^old-page(/?|/.*)$ /new-page/ [R=301,L]
or
RedirectMatch 301 ^/old-page(/?|/.*)$ /new-page/
				
			

In these examples, the “old-page” URL has been changed to “new-page”. The “R=301” portion of the rule specifies that the redirect should use the 301 status code, which indicates that the redirect is permanent. 

The “L” flag in the RewriteRule example indicates that this is the last rule to be processed and no further rules should be applied.

The “RedirectMatch” directive in the second example serves a similar purpose as the “RewriteRule” directive, but it is used specifically for matching and redirecting based on regular expression patterns.

There are two different methods shown in the example for setting up a redirect from the “old-page” URL to the “new-page” URL: the RewriteRule directive, which is part of the Apache mod_rewrite module, and the RedirectMatch directive, which is part of the Apache mod_alias module.

Both of these methods can be used to set up redirects, and the specific method you choose may depend on your needs and preferences.

The regular expression pattern used in these examples specifies that the redirect should apply to any URL that starts with “/old-page” and is followed by either a slash “/” or nothing (indicated by the “(/?|/.*)” pattern). 

This allows for the redirect to apply to both “/old-page/” and “/old-page” without also applying to similar URLs such as “/old-page-other/”.

The “$” at the end of the pattern indicates the end of the URL, and the “L” flag in the RewriteRule example specifies that this is the last rule to be processed.

The following URLs will match and be directed to a new page:

Using a redirect in the following form:

				
					Redirect 301 /old-page/ /new-page/
				
			

Without the use of regular expressions can result in some variations of the “old-page” URL ending up as 404 errors. For example, URLs that include UTM query strings such as “/old-page?utm_source=facebook.com” would not be correctly redirected and would result in a 404 error.

Similarly, URLs that do not include a trailing slash “/” at the end, such as “/old-page”, would also result in a 404 error.

To avoid this issue and ensure that all variations of the “old-page” URL are correctly redirected, it is recommended to use regular expressions as shown in the previous examples.

This allows the redirect to apply to all variations of the “old-page” URL, including those with UTM query strings and those without a trailing slash.

Redirect All Except

Suppose, you have a group of URLs that are organized into subcategories under the “/category/” URL, and you want to merge all of the subcategories into the “/category/final-subcategory/” URL.

To do this, you can use a “RewriteCond” directive to specify a condition for the redirect, and a “RewriteRule” directive to specify the actual redirect.

Here is the provided example rewritten for clarity:

				
					RewriteCond %{REQUEST_URI} !/category/final-subcategory/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(category/). /category/final-subcategory/ [R=301,L]

				
			

This example uses two “RewriteCond” directives to specify the conditions for the redirect. The first “RewriteCond” directive, “%{REQUEST_URI} !/category/final-subcategory/”, specifies that the redirect should not apply to the “/category/final-subcategory/” URL.

The second “RewriteCond” directive, “%{REQUEST_FILENAME} !-f”, specifies that the redirect should not apply to any URLs that correspond to an existing file on the server.

The “RewriteRule” directive specifies the actual redirect, which in this case is from any URL that starts with “/category/” to the “/category/final-subcategory/” URL.

This example uses a combination of “RewriteCond” and “RewriteRule” directives to set up a redirect from all URLs under “/category/” to the “/category/final-subcategory/” URL, with the exception of the “/category/final-subcategory/” URL itself.

The “RewriteCond” directive specifies the conditions for the redirect, while the “RewriteRule” directive specifies the actual redirect.

Directory Change

You can use the rule below if you did a category restructuring and want to move everything from the old directory to the new one.

				
					RewriteRule ^old-directory$ /new-directory/ [R=301,NC,L]
RewriteRule ^old-directory/(.*)$ /new-directory/$1 [R=301,NC,L]
				
			

I used $1 in the target to tell the server that it should remember everything in the URL that follows /old-directory/ (i.e., /old-directory/subdirectory/) and pass it (i.e., “/subdirectory/”) onto the destination. As a result, it will be redirected to /new-directory/subdirectory/.

Using the regular expression pattern “(/?|.)$” at the end of the “RewriteRule” directive could potentially cause problems with redirects that include a query string.

This is because the pattern would match both the optional trailing slash (“/?”) and any additional characters that follow it (“.”), including the query string.

Remove a Word from URL

The provided examples show two “RewriteRule” directives that can be used to set up redirects for URLs on a website that include the city name “Chicago”.

The first rule, “RewriteRule ^(.)-chicago-(.) http://%{SERVER_NAME}/$1-$2 [NC,R=301,L]”, is used to redirect URLs with the “chicago” string between two other strings, such as “http://yourwebiste.com/example-chicago-event/”. 

This rule uses a regular expression pattern to capture the characters that come before and after the “chicago” string, and specifies that these characters should be preserved in the destination URL.

The second rule, “RewriteRule ^(.)/chicago/(.) http://%{SERVER_NAME}/$1/$2 [NC,R=301,L]”, is used to redirect URLs with the “chicago” string between two slashes, such as “http://yourwebiste.com/example/chicago/event/”. 

This rule uses a similar regular expression pattern and target URL structure as the first rule, but is adapted to match URLs with a different format.

Both rules use the “R=301” parameter to specify that the redirect should use the 301 status code, which indicates that the redirect is permanent.

The “NC” flag stands for “No Case” and specifies that the redirect should be case-insensitive, meaning that it will apply to URLs regardless of the case of the characters. 

The “L” flag indicates that this is the last rule to be processed and no further rules should be applied.

Set a Canonical URL

It is important to have a Canonical URL for your website in order to avoid duplicate content issues. Search engines may treat different versions of a URL, such as those with “www” and those without, as separate pages with the same content. To prevent this, you should choose one version of the URL to use for your website.

If you prefer to use the “www” version, you can use the following rule in your .htaccess file:

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

If you prefer the “non-www” version, you can use this rule instead:

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

These rules will redirect users and search engines to the preferred version of your URL, with a status code of 301 indicating that the redirect is permanent.

The presence or absence of a trailing slash at the end of a URL can also affect canonicalization. To ensure that URLs with a trailing slash are treated the same as those without, you can use the following rule in your .htaccess file:

				
					RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*[^/])$ /$1/ [L,R=301]

				
			

This rule will redirect URLs that do not have a trailing slash to the same URL with a trailing slash, using a status code of 301 to indicate that the redirect is permanent.

If you prefer to remove the trailing slash instead, you can use the following rule:

				
					RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

				
			

This rule will redirect URLs that do have a trailing slash to the same URL without a trailing slash, again using a status code of 301 to indicate that the redirect is permanent.

Http to Https Redirect

To encourage website owners to use SSL, Google has encouraged the use of HTTPS. One way to migrate a website to HTTPS is to use the following rewrite rule in your .htaccess file:

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

This rule will redirect all traffic to the HTTPS version of your website, using a status code of 301 to indicate that the redirect is permanent. It will apply to both the “www” and “non-www” versions of your website.

Redirect from Old Domain to New Domain

If you need to change your domain, the following rewrite rule in your .htaccess file can be used to redirect traffic from the old domain to the new domain:

				
					
RewriteCond %{HTTP_HOST} ^old-domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.old-domain.com$
RewriteRule (.*)$ http://www.new-domain.com/$1 [R=301,L]
				
			

This rule handles both the “www” and “non-www” versions of the old domain, and redirects all traffic to the “www” version of the new domain. 

It uses a status code of 301 to indicate that the redirect is permanent.

If you use WordPress and prefer to use a plugin to handle redirects, there are many options available. 

One free plugin that is popular and has many parameters to control redirect rules is Redirection. 

You may need to read the plugin’s documentation to correctly use regular expressions for your specific needs.

Conclusion

Understanding redirects in SEO is an essential part of optimizing web pages. 

Different situations may require the use of different types of redirects, such as when migrating a website to a new domain or creating a temporary holding page for a webpage that will later be available under its normal URL.