Redirecting Visitors To Different Page - Explains two methods.

free web hosting
Open Discussion > CONTRIBUTE > The Internet > Web Design

Redirecting Visitors To Different Page - Explains two methods.

pasten
Well, almost all of you would have experienced redirecting pages while you were downloading something on the net. Redirecting users to new pages is a fact of life when programming dynamic websites. The primary reason is that you often need to redirect a user after making session state changes. For example, when you add an item to a shopping cart, you want the user to go to a page such as the current shopping cart, and you don't want to add another one of the same item to the cart again if you reload that shopping cart page. The same case if you developed guestbook where page refresh can lead to multiple posts. And in other case if a user came from search engine and the page was moved you still want that page to be accessible. Most sites achieve this with a script that processes the state change and then redirects to the page that they want the user to see.

There are essentially two ways to do it:

First Method: (preferred and best way)

This method uses the HTTP Location header, like this:

QUOTE
<?
header("Location: new_page.php");
?>
The header() function sends raw HTTP headers to the user's browser. Therefore, you need to do this before sending any other output to the browser, just as you would when setting a cookie. There are two advantages to this method. First, it is instant, and the intermediate script does not appear in a web browser's history. Second, because it is HTTP based, it does not require a web browser to process; automatic web crawlers and programs such as wget understand it.

Second Method:

However, if you would like to show an intermediate page to the user with a delay, you need to use a different method that uses the HTML <meta> tag. It's pretty simple; to send a user to a different page after displaying the current page for five seconds, put the following in your HTML header:

QUOTE
<meta http-equiv="Refresh" content="5;URL= new_page.php" />


All web browsers understand this, but automatic page crawlers sometimes do not. In addition, this intermediate page will show up in the user's browser history. Beware, page refresh in meta tags may be considered spam by search kings like google and yahoo.


Redirection's use when shifting domains:

Ok, so you were using a free subdomain like .co.nr or others. You have developed your site well, attracted some good traffic, and even probably earned some money through advertisements. You are now thinking to buy a cool .com domain. Yes! you even masked your .co.nr address to just show the same link in every page so that when you change domain your old links just dont throw page not found error on visitors face. But wait! What about the traffic which you would be recieving on the old address. If you were using a .co.nr address you had to show thier ad link on the first page, but you have your own domain right? So, the first idea of directly updating your .co.nr address to the new domain is not nice at all.

So you already know that you can use a page in between containing "This site is being redirected to new address" and redirect after five seconds. But .co.nr people are smart and wont allow you to do this neither direct redirecting using php method. In addition to bots they manually check the users subdomains. So what you can do???

Simple. Just create an exact replica of your main index page and add the ad link which they want you to show. Change every link on that page with thier respective address in your new domain. Now link this page to your old .co.nr address. That's it. Now your visitors coming from new domain won't be seeing any .co.nr ad link. And in the process also taking care of the visitors from the old address. Also you can host this page on your current host and can even add a statistic logging code to this page to see how many people from which place are still coming through your old address.

These things would not have been possible if you directly linked to your new address. Was it? I have seen majority (even myself) of people using .co.nr domains and this may be the only method you would use for this major change.

 

 

 


Reply

moodsey211
There is also another way of doing this. through the used of javascripts.

CODE
<scirpt>
setTimeout("foo()",5);

function foo()
{
window.href = "otherpage.html";
}
</script>


this will actually work just like have the meta tag but search engines would not flag your web page as a spam. If you don't want to ensure that there is not output before calling the function (i.e. header function) then you can do this by invoking the function ob_start() which buffers the page in the server before sending it to the clients browser. so you can rest assure that your header will still work even if there is already an output sent.

Reply

delivi
Page redirection in various coomon web development languages,

java script:
CODE
<script type="text/javascript">
   window.location = "http://www.google.com/"
</script>


If you want a time delay use the following code,

CODE
<script type="text/javascript">
    function handleRedirect() {
        setTimeout(redirectTo("http://www.trap17.com/"), 5000); //Redirect after 5 Seconds
    }

    function redirectTo(url) {
        window.location = url;
    }

    window.load = handleRedirect();
</script>


-----------------------------------------------------------------------------------------------------------

The 301 Redirect is used to point to new page or new website the Search Engine Friendly way. The 301 redirect is interpreted as "Permanently Moved".

Here is how we do 301 redirect in PHP:

CODE
<?
   Header( "HTTP/1.1 301 Moved Permanently" );
   Header( "Location: http://NEW_DOMAIN/" );
?>

Make sure that you put this code in the first line of the page.

301 redirect using Java Server Pages (JSP):

CODE
<%
   response.setStatus(301);
   response.setHeader( "Location", "http://NEW_DOMAIN/" );
   response.setHeader( "Connection", "close" );
%>


301 redirect using Ruby on Rails:
CODE
def ACTION_NAME
   headers["Status"] = "301 Moved Permanently"
   redirect_to "http://NEW_DOMAIN/"
end


Replace the ACTION_NAME with the action that you want to handle the redirection.

301 redirect using .htaccess.

Create a .htaccess file in the root directory of your website and put the following in it,
CODE
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://NEW_DOMIAN/$1 [R=301,L]


Replace NEW_DOMAIN with your new domain or the updated page path in the above code snippets.

 

 

 


Reply

Erdemir
How about this redirect javascript. Too short.
CODE
<script>location.href="http://www.example.com/file.php";</script>

OR

If your page is in a frame and you want the whole page redirects.
CODE
<script>top.location.href="http://www.example.com/file.php";</script>

Reply

gogoily
Try this codes:
CODE
<?php
header("refresh:0;url='http://www.yahoo.com/'");
?>

Reply

LooneyMapleStory
How would i redirect when using Php?

Reply

gogoily
QUOTE(LooneyMapleStory @ Aug 9 2008, 02:55 AM) *
How would i redirect when using Php?

At the very beginning of your script, adding the following codes:
CODE
<?php
header("location:somepage.php");
?>

Reply

jlhaslip
see the posts above yours.

Reply

Stridr
I believe the best way is still this

<?
header("Location: new_page.php");
?>

No need to complicate things, this is the easiest and fuss free way to go about doing it. Cheers.

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Recent Queries:-
  1. response.setheader vs meta tags - 4.10 hr back. (1)
  2. automatically redirecting jsp page to a different link - 4.62 hr back. (1)
  3. script to redirect page after time - 9.44 hr back. (1)
  4. web coding, how to, close a page after redirect - 16.99 hr back. (1)
  5. php redirect new window - 18.57 hr back. (1)
  6. redirect to a different page server admin - 19.51 hr back. (1)
  7. .net output different page without redirect - 20.07 hr back. (1)
  8. redirect page to different domain - 22.50 hr back. (1)
  9. php redirect different pages bots users - 23.25 hr back. (1)
  10. how redirect the page in waiting the in seconds in jsp - 23.77 hr back. (1)
  11. php redirecting web page with delay - 23.86 hr back. (1)
  12. java load new page after delay - 25.12 hr back. (2)
  13. time delay web page redirecting - 25.88 hr back. (1)
  14. how to redirect a subdomain to a different page - 34.69 hr back. (1)
Similar Topics

Keywords : redirecting, visitors, page, explains, methods,

  1. Script.aculo.us - A Library Of Ajax Scripts To Improve Your Website's Design
    many ways to impress your visitors (0)


      Looking for redirecting, visitors, page, explains, methods,

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for redirecting, visitors, page, explains, methods,

*MORE FROM TRAP17.COM*
advertisement



Redirecting Visitors To Different Page - Explains two methods.



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE