Results 1 to 3 of 3

Thread: Redirect script

  1. #1
    Join Date
    Nov 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Redirect script

    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
    Walking Sticks

  2. #2
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Mary View Post
    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

  3. #3
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    1. If you are looking for redirecting to a page using JavaScript then check the following code

    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
    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •