PDA

View Full Version : Redirect script



Mary
11-16-2006, 09:53 PM
Hi, Can some one please help me.

I am trying to make an automatic page forward. For example, when a visitor types is a url 1, there will be some codes on that page that will automatically rediret the visitor to url 2.

_____________________

Web Design London (http://www.datadial.net/)
Walking Sticks (http://www.walking-stick.net)

mwinter
11-17-2006, 02:41 AM
I am trying to make an automatic page forward. For example, when a visitor types is a url 1, there will be some codes on that page that will automatically rediret the visitor to url 2.

Ideally you should use HTTP to perform redirects, though how you do that depends on your server and what features you have available. For example, one could use distributed configuration files (.htaccess) with Apache, or have a server-side language like PHP or ASP handle the request.

There are other means, but these either rely on optional features, break with or are frowned upon by search engines, or disrupt the user's browsing history.

Mike

codeexploiter
11-17-2006, 03:58 AM
1. If you are looking for redirecting to a page using JavaScript then check the following code



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript">
function redirect()
{
window.location = "http://www.google.com"; //specify the destination page here.
}
</script>
</head>

<body onload="setTimeout('redirect()',5000);">
You will be redirected to the main page in a moment...............
</body>
</html>


I've used setTimeout() just to give a delay before the redirection.


2. Using the META tag of HTML you can perform the redirection. Refer the following code


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Redirecting using META tag</title>
<meta http-equiv="refresh" content="5;URL=http://www.google.com" />
</head>

<body>
You will be redirected to the main page in a moment...............
</body>
</html>


3. Using a 301 redirect (using .htaccess file)
How to implement the 301 Redirect

Hope your webserver supports .htaccess file if then you've created/editing the same in the following manner
1. Place this code in your .htaccess file:

redirect 301 /oldsite/oldpage.html http://www.you.com/new.htm

2. If the .htaccess file already has lines of code in it, skip a line, then add the above code.

5. Save the .htaccess file

6. Upload this file to the root folder of your server.

7. Test it by typing in the old address to the page you've changed. You should be immediately taken to the new location.

4. Using server-side scripting tools like ASP or PHP you can redirect to new locations also.