Nov 21, 2009
Pages: 1, 2

Redirecting Visitors To Different Page - Explains two methods.

free web hosting

Read Latest Entries..: (Post #12) by iGuest on Oct 29 2009, 12:55 PM.
How browsing history page of website Redirecting Visitors To Different Page How browsing history page of website. When user browse through pages of website at the end user can see which pages he browsed.[using PHP sessions] -question by Manjunath
Read the FIRST post of this Topic. - Express your Opinion! Contribute Knowledge :-).

Open Discussion > MODERATED AREA > The Internet > Web Design

Redirecting Visitors To Different Page - Explains two methods.

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

 

 

 


Comment/Reply (w/o sign-up)

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.

Comment/Reply (w/o sign-up)

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.

 

 

 


Comment/Reply (w/o sign-up)

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>

Comment/Reply (w/o sign-up)

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

Comment/Reply (w/o sign-up)

LooneyMapleStory
How would i redirect when using Php?

Comment/Reply (w/o sign-up)

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");
?>

Comment/Reply (w/o sign-up)

jlhaslip
see the posts above yours.

Comment/Reply (w/o sign-up)

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.

Comment/Reply (w/o sign-up)

(G)Chris
How to redirect visitors from specific referring domains?
Redirecting Visitors To Different Page

Great info here! Using .Htaccess file, how can I redirect visitors from certain referring domains to a landing page?  We advertise on Facebook, myspace, sherdog.Com and etc and would like visitors who click on our ads to be redirected to a landing page before they enter the site.  This way we can change the landing page every so often or change the htaccess to point to a new page when we have a promotion going on.

 Just curious if I can do this with htaccess by listing out the referring domains to send all visitors to landingpage.Php or whatever we call it.

Thanks!

Chris

-reply by Chris

Comment/Reply (w/o sign-up)

Latest Entries

iGuest
How browsing history page of website
Redirecting Visitors To Different Page

How browsing history page of website. When user browse through pages of website at the end user can see which pages he browsed.[using PHP sessions]

-question by Manjunath

Comment/Reply (w/o sign-up)

rpgsearcherz
Very interesting information. Is it possible to add colors and text to the screen when this is in effect as well?

I've been messing with creating custom 404's for CMS's to where it will automatically take you to the home page if you type a wrong address, but I am only able to do it on a white background w/ black text. More or less it just says "Redirecting..." or something like that.

I would love to be able to change the color to look the same as the CMS... It just doesn't feel like it fits right.

Also, in your method one. This is just telling the browser that instead of, say "jokes.html" you are on "index.html"? Like you load up the jokes but if you refresh it would take you to index? (Assuming you set it as "index.html" I mean.

Comment/Reply (w/o sign-up)



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*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Pages: 1, 2

Searching Video's for redirecting, visitors, page, explains, methods,
See Also,
advertisement


Redirecting Visitors To Different Page - Explains two methods.

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com