Redirects

Definition

Redirects are automatic forwarding of URLs. There are server-side and client-side redirects. With server-side redirects, a command (redirection) is stored in a file. When the corresponding URL is called, the server immediately redirects it to the new destination. The most common server-side redirects are 301 & 302 redirects. With client-side redirects, no change is made to the server, as the redirect must be stored in the source code of the page. In terms of search engine optimization, client-side redirects are not recommended.

It should be noted that each redirect is an additional work step for the server. These additional steps can affect the PageSpeed and thus the performance of a website. Also, redirect chains should be avoided, because a search engine can no longer follow them after a certain amount of redirects and the crawler issues an error.

Application example

301 redirects are used, for example, in the event of a domain move, a change in the website protocol or a change in the URL structure. The advantage of 301 redirects is that 100% of the link juice is inherited and that a clear signal is sent to the search engine that the requested resource can be found permanently under a different URL. 301 redirects can be stored in a .htaccess file or via PHP. If the redirect is inserted via PHP, the server-side code must look like this:

302 redirects are used, for example, for redirecting product URLs or redirects for tracking or website testing. Such redirects inherit 100% of PageRank and signal to the user that the requested resource is available, but is temporarily located somewhere else. The server-side PHP code for a 302 redirect should look like this:

<?php
header(“http/1.1 302 Found”);
header(“Location:https://www.domain-neu.de”);
header(“Connection: close”);
?>

JavaScript is used to forward the redirects client-side. The two most popular ways are locatin.href and location.replace. These should look like the following:

window.location.href=”http://www.domain.de”;

window.location.replace(http://www.domain.de);