Saturday, October 11, 2008

Three Ways to Redirect Site

Because of some reason you want to redirect your site to another site. There are three ways that you can use to redirect your site.

1. Meta Refresh
2. Javascript
3. PHP

1. Meta Refresh
Put this code into your page that you want to redirect. Put this script on
<head></head>

<meta http-equiv="refresh" content="second; URL=other_url">

second = How long in second you your visitor will be redirected. Example: 2
other_url = New site that should be visited by user.

In some case, browser can't redirect to another site automatically. To solve the problem you can add direction site address. It means let people click the link to visit direction site address.

Example:


<html>
<head>
<title>You'll be redirected after 2 seconds</title>

<meta http-equiv="refresh" content="2; URL=http://hardono.melesat.com">
</head>
<body>
<a href="http://hardono.melesat.com">Click here.</a> if you don't redirect in 2 seconds
</body>
</html>


If you want to redirect without rest you just nedd to change content="0;

2. Javascript
With javascript you can also create redirect function

Without time

<html>
<head>
<title>You'll be redirected</title>
<script type="text/javascript">
<--
window.location = "http://hardono.melesat.com"
//-->
</script>
<body>
If your browser doesn't automatically redirect, please <a href="http://hardono.melesat.com";gtclick here.</a>
</body>
</html>


With time
<html>
<head>
<title>You'll be redirected after 2 seconds</title>
<script type="text/javascript">
<!--
window.setTimeout('window.location="http://hardono.melesat.com"; ',2000);
//-->
</script>
<body>
If your browser doesn't automatically redirect, please <a href="http://hardono.melesat.com";>click here.</a>
</body>
</html>


Numeral 2000 is in milisecond or 2 second. If you want to set 10 second just type 10000 (10 x 1000)

3. Using PHP
If use PHP you can use this script

<?php
header("location:web_address");
?>


Change web_address with your address.

Have a nice try!

No comments:

Post a Comment