If you work with web servers (such as Nginx or Apache HTTPD) or you code your own web-application, you have most likely already come across the HTTP response (or status) codes 301 and 302. These codes represent a redirect of the currently accessed URL to a new destination URL. But what are the differences between 301 and 302 redirects and how do they affect your SEO score?
The difference between these two response codes is quite simple:
Both redirect types fall under the "redirect category" of HTTP status codes, represented by the leading number 3.
Note: HTTP status codes come in five categories within the official registry. The first digit of each one displays its response category. All codes in the redirect category start with 3.
The status code is important because it involves the so-called "search engine equity" a specific URL has built up. When an old page or site has moved, you need to redirect search engines to the new page correctly. The redirect status makes the difference between building on top of all past SEO efforts and indexed results or starting from the ground up. Another risk is competing against your own old page for search engine traffic.
If you can redirect your URL properly, you maintain your link capacity and search engine rankings as you move all data to your new page. A 302 does not maintain your capacity and rankings. It just redirects the user to the new address so they don't get an error page or a broken link.
A 301 redirect signifies that the content on the page has moved permanently. The new page has replaced the old one. The 301 helps change the site's address on the Internet when it appears in Search Engine results. The old URL's existing link and SEO value transfers to the new URL.
A 302 redirect will send users and search engines to a new site for a limited period until you remove the redirect. The 302 status might be translated as HTTP 1.0 (moved temporarily) or HTTP 1.1 (302 found).
It's easier to set up a 302 - all you need is a meta tag in your HTML code. If you want to set up a 301, you need access to server files, such as web server config or web-application code.
Using a 302 instead of a 301 becomes a problem when the search engine tries to find out which page has more SEO value. It will list just one page version in the results and could list the wrong one. With time, this problem will compound as a redirect chain builds on top of older pages.
When setting up a redirect, always make sure to verify the destination URL. Is the destination URL really showing content with a proper status code (such as 200)? Mistakes do sometimes happen. The worst case would result in a broken redirect, or a redirect loop.
Let's take the following practical example. You have set up a website under the domain "localhost". You want to redirect the page about.html to company.html. But you mistakenly copied the same redirect refresh meta tag from about.html into company.html:
<meta http-equiv="refresh" content="0; url=http://localhost/company.html">
Note: This simple kind of redirect, using the HTML meta tag refresh, does not automatically create a redirect status code 301 or 302. But it can be used as a valid redirect by telling the browser a destination URL to refresh the page. It is, in this case, used as the perfect example of a redirect loop.
This means:
You notice that the second redirect will run forever, as the destination URL wants to redirect (again) to the same URL.
Under normal circumstances with proper redirect return codes (30x), modern browsers detect a redirect loop and show a warning:
But if you thought, you could simply redirect from a domain to another domain to yet another domain and do this forever, keep in mind that redirects have a limit. This is called the maximum number of redirects. When this limit is reached, the browser won't go on and will show a warning ERR_TOO_MANY_REDIRECTS.
According to this and this answer on StackOverflow, the maximum amount of redirects a modern browser allows is between 16 and 20, depending on the browser.
You should use a 301 when you're merging two sites when you want to transfer a domain, when you use several different URLs to access a site, and when you've changed your domain permanently. Other situations are if you've moved your site to a new content management system, you're adding a secure socket layer (https), or your URL structure has changed.
One situation would be in an e-commerce setting. If you have a seasonal product or one that's out of stock, it's a good idea to create a 302 and send users to your store's category page. They will see similar products that are currently in stock. The 302 message tells search engines the page is temporarily offline, and its SEO value is not transferred to another URL.
When using a browser, you don't necessarily become aware of a redirect. A redirect is followed up on quickly, you might only notice an URL change in the address bar. Redirects can also become cached inside the browser cache. This can be quite annoying for redirect testing and verification.
By using command line tools, such as curl or wget, you can analyze the "location" response header which shows the destination URL:
ckadm@mintp ~ $ curl -I https://www.claudiokuenzler.com/about
HTTP/2 301
server: nginx
date: Tue, 13 Feb 2024 14:15:13 GMT
content-type: text/html; charset=iso-8859-1
location: http://www.claudiokuenzler.com/about/
strict-transport-security: max-age=63072000
This allows you to manually follow the redirects and verify a redirect was correctly configured in your web application or web server.
Search engines react differently to 301 and 302 return codes, so it's essential to set up the right one. If you don't, the search engine might send traffic the wrong way. You can prevent this by knowing the difference, which will also ensure you preserve all previous SEO value.
No comments yet.
AWS Android Ansible Apache Apple Atlassian BSD Backup Bash Bluecoat CMS Chef Cloud Coding Consul Containers CouchDB DB DNS Database Databases Docker ELK Elasticsearch Filebeat FreeBSD Galera Git GlusterFS Grafana Graphics HAProxy HTML Hacks Hardware Icinga Influx Internet Java KVM Kibana Kodi Kubernetes LVM LXC Linux Logstash Mac Macintosh Mail MariaDB Minio MongoDB Monitoring Multimedia MySQL NFS Nagios Network Nginx OSSEC OTRS Observability Office OpenSearch PGSQL PHP Perl Personal PostgreSQL Postgres PowerDNS Proxmox Proxy Python Rancher Rant Redis Roundcube SSL Samba Seafile Security Shell SmartOS Solaris Surveillance Systemd TLS Tomcat Ubuntu Unix VMWare VMware Varnish Virtualization Windows Wireless Wordpress Wyse ZFS Zoneminder