This a demonstration page for redirection.htm you will be automatically redirected to that page in 30 seconds.
None of these client-side methods can return as server-side code such as 301, 302 etc.
The simplest method is probably a meta tag in the <head> section of a web page and takes the form...
<meta http-equiv="refresh" content="time_in_seconds; url=URL_to_redirect_to">
time_in_seconds can be any value you like. A value of 0 will cause immediate redirection.
The code on this page is...
<meta http-equiv="Refresh" content="30; url=redirection.htm">
It will be beneficial to your visitors if you put some sort of text on the page to explain why they are being redirected. It also helps if you put a HTML link on the page and the URL of the page they are being redirected to. The HTML link will help search engines find your new page and the URL will help people who have automatic redirection in their browsers turned off.
You can also use an element's onclick property to trigger Document Object Model (DOM) events or run code, usually JavaScript, on a page.
There is something a little odd about window.location.href, window.location, location.href, and location. The ones without .href refer to objects, while the ones with .href refer to strings. The reason they all work is that the DOM knows what to do when a URL string is assigned to an object. So, for the purposes of this page they are all equal!
The following buttons will all take you to this back to the main redirection page!
The code for all the buttons is similar to...
<button onclick="window.location.href='redirection.htm'">text</button>
location has other methods that can be used. One of them is .assign
<button onclick="location.assign('redirection.htm')">location.assign()</button>
Another is .replace. This behaves differently to the other methods on this page in that it replaces the browser history with the new URL and that means the visitor cannot use the back button to navigate back to the original page.
<button onclick="location.replace('redirection.htm')">location.replace()</button>
It is possible to use JavaScript or other code to introduce a timed delay to the redirect. This example uses an inline script:
<button onclick="setTimeout(function(){location='redirection.htm'},2000);">Timed location</button>