Learn

Resources to understand all relevant details about status codes and redirects.

Client-side vs server-side redirects


Client-side redirects and server-side redirects are two different methods used to redirect users from one webpage to another. Client-side redirects happen within the user's browser using JavaScript or HTML, while server-side redirects are handled at the server level through HTTP responses and instructing browsers to go to a different URL.

Client-side redirect

A client-side redirect occurs after the web page has been loaded in the user's browser using JavaScript or meta refresh tags embedded in HTML code.

In this method, when a user visits a specific webpage, they may see some content briefly before being automatically redirected to another page without making any additional requests to the server.

These redirects occur entirely on the user's device and do not involve any communication with the server.

NOTE  httpstatus.io can only check and follow server-side redirects.

JavaScript and meta refresh redirects are two different approaches to client-side redirecting a web page to another URL.


JavaScript redirects

In JavaScript, you can use the window.location object or window.location.href property to redirect the page to a new URL. The redirection happens dynamically on the client-side, meaning it occurs after the initial page has finished loading. JavaScript redirects give developers more control over when and how the redirect occurs. It allows for conditional redirects based on certain criteria or events.

Example (redirects after 3 seconds):

setTimeout(function() {
    window.location.href = "https://example.com";
}, 3000);

Meta refresh redirects

A meta refresh is an HTML tag used within the <head> section of an HTML document. It instructs browsers to automatically load a new URL after a specified time interval. Meta refreshes work without any scripting support from clients as they are part of standard HTML usage. The redirection happens at the beginning of page loading before any content is displayed in most cases.

Example (redirects after 5 seconds):

<meta http-equiv="refresh" content="5; URL='https://example.com'" />

In this example, it will wait for 5 seconds (specified in content) and then automatically redirects to https://example.com.

Overall, while both methods achieve page redirection, JavaScript offers more flexibility and control over when and how it occurs compared to meta refresh redirects which have limited options but don't require scripting support from clients.

Server-side redirect

A server-side redirect, also known as an HTTP redirect or server header response, is implemented on the server and is triggered before any content is sent to the client's browser.

When a user requests a particular URL, the server checks if there is a redirection rule configured for that URL, and if so, it returns an HTTP response with a status code (usually 301 or 302) indicating that the requested resource has been permanently or temporarily moved elsewhere. The browser then makes a new request to the redirected URL.

Semantic difference for search engines

Client-side and server-side redirects are semantically different, and this distinction is important for search engines.

Search engines generally interpret server-side redirects more accurately than client-side ones since they directly read and understand HTTP headers sent by servers.

Using proper server-side redirection methods helps ensure that search engines correctly attribute rankings, preserve link equity (SEO value passed from old URLs), and display relevant content in search results.

Google Search understands and follows client-side and server-side redirects, but a server side redirect has the highest chance of being interpreted correctly by Google. When server-side redirects aren't possible to implement on your platform, meta refresh redirects may be a viable alternative. Be aware that Google Search interprets a 'delayed' meta refresh redirect (the above example with a 5-second delay) as a temporary redirect. An instant meta refresh redirect, without a specified delay, is interpreted by Google Search as a permanent redirect.

Google recommends only to use JavaScript redirects if you can't do server-side or meta refresh redirects. Google Search interprets and executes JavaScript using the Web Rendering Service (WRS) once crawling of the URL has completed. While Google attempts to render every URL Googlebot crawled, rendering may fail for various reasons. This means that if you set a JavaScript redirect, Google might never see it if rendering of the content failed.

This website uses cookies to ensure you get the best experience. By using this website, you acknowledge that you understand and agree to our Privacy Policy and Terms and Conditions.