On the internet, everything has its place, defined by its URL. If for some reason it changes, it creates a number of difficulties – both for Google's crawlers, which are responsible for ranking the page, and for users searching for specific content. However, there is a solution – a 301 redirect is the virtual equivalent of changing your mailing address. Learn how it works and what types of 301 redirects can be used.
What is a 301 redirect?
A 301 (Moved Permanently) redirect is a mechanism that indicates that a page has been moved to a different address . It works automatically – meaning it doesn't display a "move" message, but instead redirects you to the correct page at the new URL . This saves search engine robots and internet users from having to wander around looking for specific content.
There are several types of redirects, but 301 is the most popular. It signifies a permanent relocation, meaning a permanent change to the website's address. This solution is very convenient from a user perspective and, at the same time, crucial for SEO. Thanks to the redirect, the website doesn't lose its established positioning or strength and can continue to build on it.
When is a 301 redirect used? Most common types
Constructing a 301 redirect may be necessary for various reasons. This is usually done in the .htaccess file—just use the appropriate code. There are several common types of redirects. Examples, along with the required code (replace "yourwebsite.com" with your own website address), can be found below.
(The rest of the article can be found below the form)
- 301 redirects from "www" to "no www" addresses
Website addresses can appear with or without the leading "www." If left unaddressed, this can create confusion, with traffic being distributed across two separate addresses, which is particularly detrimental to SEO.
Therefore, in such cases, a 301 redirect is most often used, allowing users to choose their preferred website address. This ensures that users will reach the target page regardless of whether they type "www.yourwebsite.pl" or "yourwebsite.pl" into the browser bar. This solution positively impacts optimization and enhances user experience.
Sample code:
RewriteCond %{HTTP_HOST} ^www.twojastrona.pl$
RewriteRule (.*)$ http://twojastrona.pl/ [R=301,L]
Changing a domain name is a relatively common practice. In such cases, it's important to ensure redirection so that users can easily find the new address and that Google doesn't consider the transferred content as duplicate content , which is highly inadvisable for SEO purposes.
It's crucial to ensure that the 301 redirect applies not only to the home page but also to other tabs. The best solution is to use these to create direct paths to the new addresses for each subpage. It's worth the effort, if only to avoid discouraging users by hitting a wall, meaning they'll land on a page that no longer exists. This is also the only way to migrate your site without losing traffic.
It's best to implement a 301 redirect before migrating your data to the new address. This will ensure that crawlers correctly interpret your actions as a site move, not as creating a completely new site with duplicate content.
Sample code:
RewriteCond %{HTTP_HOST} ^yoursite.pl$
RewriteRule (.*)$ http://twojanowastrona.pl/ [R=301,L]
Using the SSL protocol involves changing the address from HTTP to HTTPS. This also requires redirection.
Sample code:
RewriteCond %{HTTPS} !=on
RewriteRule (.*) https://%{HTTP_HOST}/ [R=301,L]
- A slash ("/") at the end of the address
The same address, differing only by a slash at the end (e.g., "www.yourwebsite.pl" and "www.yourwebsite.pl/"), is treated as two separate pages by Google. Failure to redirect in this area is a very common mistake, causing the algorithm to interpret your content as duplicate content, making it virtually impossible to achieve a high ranking in search results.
Sample code:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ / [L,R=301]
The wildcard feature helps you easily create new subdomains. However, in practice, it also means that entering any string of characters before your website's address will display its content, effectively creating a duplicate. Sometimes, Google crawlers index such pages, creating incredible chaos. Search results may then display several (or even dozens!) versions of the same address . For example, for example, www.yourwebsite.pl, it may also display www.www.yourwebsite.pl, www.yourwebsite.pl, or yourwebsite.yourwebsite.pl. This is very dangerous and may result in penalties from Google. The solution? A 301 redirect, which will redirect users and Google crawlers from each subdomain to the main page.
RewriteCond %{HTTP_HOST} ^(.+).yoursite.pl$
RewriteRule (.*)$ http://twojastrona.pl/ [R=301,L]
Other types of redirects
As a reminder, a 301 redirect is only used when a website's address is permanently changed . However, there are many other ways to redirect users to a different address and send a message to search engine robots. Other available redirect types include:
- 302 (Found) – temporary, allowing content to be moved to another address and then returned to the original source;
- 303 (See Other) – used with forms sending data via HTTP POST, enabling redirection to a specific address in response to that form;
- 304 (Not Modified) – informs the browser that the data in its memory is current, has not changed, and therefore does not need to be downloaded from the source;
- 305 (Use Proxy) – allows the use of a given resource only when using a specific proxy server, displays a message with the server address;
- 307 (Temporary Redirect) – temporary redirect, does not allow changing the request method from POST to GET.
What to remember when using 301 and other redirects?
It's worth remembering that redirects are not only beneficial for users but also facilitate the work of Google robots and help ensure proper indexing of the site. Therefore, they have a positive impact on both UX and SEO. When used correctly, they can painlessly move pages to new addresses and allow for many other activities without affecting the site's ranking.
However, caution should be exercised when using different types of redirects. Using too many commands can create a loop, resulting in a 310 error (Too many redirects), which prevents you from reaching a specific page.
Summary
The above article covers the following topics:
- What is "Moved Permanently"? 301 Status Explained
- Status codes and redirects: 301, 302 and their impact on indexing