A Guide to Redirects: How, Where, and When to Use Them
Posted: Mon Dec 09, 2024 7:07 am
Redirects are an integral part of technical website optimization, which the vast majority of webmasters and SEO specialists encounter from time to time. If you have not used redirects before and do not know where to start, this guide is for you. In one article, we have compiled a list of the main redirects and examples of their use, as well as a list of potential errors and problems that may arise due to improper redirect settings.
What is a redirect?
Redirect is a mechanism for automatically redirecting users from one URL to another. Most often, redirection is implemented on the server side using special instructions in server configuration files. For sites on Apache servers, the .htaccess file is used; for those running on nginx, nginx.config. Redirection can also be configured using PHP, HTML, and JavaScript.
What are redirects and when to use them?
There are 10 different types of redirects, including Meta taiyuan mobile phone numbers database Refresh. But in practice, only a few are used.
301 Moved Permanently
301 redirect is the absolute leader in terms of frequency of use. It is used for permanent redirection and transfers link weight from the initial address to the final URL, similar to regular links.
301 redirect is used for several purposes:
Constant redirection from addresses of pages that no longer exist or are no longer relevant.
Redirect to the correct address after moving or redesigning the site.
"Gluing" (combining two addresses in the search engine index) of duplicate pages, including full copies available at different addresses; identical versions of the same page with different protocols (HTTP and HTTPS), with or without the www. prefix, as well as pages with or without trailing slashes in URLs.
Redirect to a file with a changed extension.
For example, a 301 redirect, responsible for redirecting from addresses with the www. prefix to addresses without a prefix, looks like this:
302 redirect is used for temporary redirection and is most often configured at the stage of testing new pages and redesigning a website. Pages from which 302 redirect is set are not “glued” to the final URL, that is, they continue to be indexed independently and exist in search engine indexes. This feature of 302 redirect is associated with an error often made by inexperienced SEO specialists. Its essence is that to eliminate duplicate pages and index only one correct URL, 302 redirect is used instead of 301, which causes extremely undesirable duplicates to appear in the index.
302 redirect transfers link weight in the same way as 301. Note separately that depending on the HTTP version, the response code may differ - 302 Moved Temporarily in the case of HTTP 1.0 and 302 Found on sites with HTTP 1.1.
An example of using a 302 redirect is to temporarily redirect a user to a sale or promotion page without changing the original product/service page. It will look like this:
Redirect 301 /old/black-dress-1.html
Another common example is redirection to the mobile version of the site, which is located on a dedicated subdomain. Since indexing of both versions is important in this case, 302 redirect is perfect for this purpose. It will look like this:
RewriteCond %{HTTP_USER_AGENT} (?i:midp|samsung|nokia|j2me|avant|docomo|novarra|palmos|palmsource|opwv|
chtml|pda|mmp|blackberry|mib|symbian|wireless|nokia|hand|mobi|phone |
cdm|upb|audio|SIE|SEC|samsung|HTC|mot-|mitsu|sagem|sony|alcatel|lg|eric|vx|NEC|philips|mmm|xx|panasonic|sharp|
wap|sch|rover|pocket |benq|java|pt|pg|vox|amoi|bird|compal|kg|voda|sany|
kdd|dbt|sendo|sgh|gradi|jb|dddi|moto|iphone|android) [NC]
Like 302, 307 redirect is used for temporary redirection and does not involve "gluing" URLs. The key difference from 302 Moved Temporarily is that with 307 redirect you can tell search engines that your server is compatible with HTTP 1.1, and that there is no need to cache the final page of the redirect.
An example would be a redirect to the authorization page, which will be performed under certain conditions:
What is a redirect?
Redirect is a mechanism for automatically redirecting users from one URL to another. Most often, redirection is implemented on the server side using special instructions in server configuration files. For sites on Apache servers, the .htaccess file is used; for those running on nginx, nginx.config. Redirection can also be configured using PHP, HTML, and JavaScript.
What are redirects and when to use them?
There are 10 different types of redirects, including Meta taiyuan mobile phone numbers database Refresh. But in practice, only a few are used.
301 Moved Permanently
301 redirect is the absolute leader in terms of frequency of use. It is used for permanent redirection and transfers link weight from the initial address to the final URL, similar to regular links.
301 redirect is used for several purposes:
Constant redirection from addresses of pages that no longer exist or are no longer relevant.
Redirect to the correct address after moving or redesigning the site.
"Gluing" (combining two addresses in the search engine index) of duplicate pages, including full copies available at different addresses; identical versions of the same page with different protocols (HTTP and HTTPS), with or without the www. prefix, as well as pages with or without trailing slashes in URLs.
Redirect to a file with a changed extension.
For example, a 301 redirect, responsible for redirecting from addresses with the www. prefix to addresses without a prefix, looks like this:
302 redirect is used for temporary redirection and is most often configured at the stage of testing new pages and redesigning a website. Pages from which 302 redirect is set are not “glued” to the final URL, that is, they continue to be indexed independently and exist in search engine indexes. This feature of 302 redirect is associated with an error often made by inexperienced SEO specialists. Its essence is that to eliminate duplicate pages and index only one correct URL, 302 redirect is used instead of 301, which causes extremely undesirable duplicates to appear in the index.
302 redirect transfers link weight in the same way as 301. Note separately that depending on the HTTP version, the response code may differ - 302 Moved Temporarily in the case of HTTP 1.0 and 302 Found on sites with HTTP 1.1.
An example of using a 302 redirect is to temporarily redirect a user to a sale or promotion page without changing the original product/service page. It will look like this:
Redirect 301 /old/black-dress-1.html
Another common example is redirection to the mobile version of the site, which is located on a dedicated subdomain. Since indexing of both versions is important in this case, 302 redirect is perfect for this purpose. It will look like this:
RewriteCond %{HTTP_USER_AGENT} (?i:midp|samsung|nokia|j2me|avant|docomo|novarra|palmos|palmsource|opwv|
chtml|pda|mmp|blackberry|mib|symbian|wireless|nokia|hand|mobi|phone |
cdm|upb|audio|SIE|SEC|samsung|HTC|mot-|mitsu|sagem|sony|alcatel|lg|eric|vx|NEC|philips|mmm|xx|panasonic|sharp|
wap|sch|rover|pocket |benq|java|pt|pg|vox|amoi|bird|compal|kg|voda|sany|
kdd|dbt|sendo|sgh|gradi|jb|dddi|moto|iphone|android) [NC]
Like 302, 307 redirect is used for temporary redirection and does not involve "gluing" URLs. The key difference from 302 Moved Temporarily is that with 307 redirect you can tell search engines that your server is compatible with HTTP 1.1, and that there is no need to cache the final page of the redirect.
An example would be a redirect to the authorization page, which will be performed under certain conditions: