Jump to content

saila.com

Online media matters

How do I make a page redirect the user elsewhere?

To redirect a user to another page, you can put a <meta> inside the <head> tags. The following would automatically redirect someone to http://www.example.com:
<meta http-equiv="refresh" content="0;URL=http://www.example.com/" />

The big issue with this method is the redirect page is added to the user’s history, potentially creating a loop (when users press the back button they land on the redirect page, which in turn takes them to the target page). You can get around this using JavaScript, though:
if(document.images) location.replace("http://www.example.com/");
else location.href = location.href("http://www.example.com/");
.

(Browsers that don’t support JavaScript 1.0 need the first line.)

By combining these two methods (putting the JavaScript before the <meta>), you should be able to redirect most browsers to a new page.

Save a copy of a redirect template for your own use.