|
|
|
|
![]() ![]() |
Jul 26 2008, 01:06 PM
Post
#1
|
|
|
Newbie [Level 3] ![]() ![]() ![]() Group: [HOSTED] Posts: 48 Joined: 19-September 06 From: **Encrypted** Member No.: 30,215 |
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 <? 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.header("Location: new_page.php"); ?> 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. |
|
|
|
Jul 28 2008, 01:49 AM
Post
#2
|
|
|
Newbie [Level 3] ![]() ![]() ![]() Group: Members Posts: 40 Joined: 10-July 08 From: Cebu City Philippines Member No.: 64,841 |
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. |
|
|
|
Jul 28 2008, 08:59 PM
Post
#3
|
|
|
Trap Grand Marshal Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 1,314 Joined: 11-January 06 From: Chennai, India Member No.: 16,932 |
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. |
|
|
|
Aug 2 2008, 11:10 PM
Post
#4
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 217 Joined: 12-May 08 From: Istanbul, Turkey Member No.: 62,045 |
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>
This post has been edited by Erdemir: Aug 2 2008, 11:11 PM |
|
|
|
Aug 6 2008, 07:20 AM
Post
#5
|
|
|
Member [Level 3] ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 99 Joined: 30-October 05 Member No.: 13,571 |
Try this codes:
CODE <?php
header("refresh:0;url='http://www.yahoo.com/'"); ?> |
|
|
|
Aug 9 2008, 02:55 AM
Post
#6
|
|
|
Newbie [Level 2] ![]() ![]() Group: [HOSTED] Posts: 36 Joined: 6-August 08 From: Under Your Bed! Member No.: 66,070 |
How would i redirect when using Php?
|
|
|
|
Aug 9 2008, 03:25 AM
Post
#7
|
|
|
Member [Level 3] ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 99 Joined: 30-October 05 Member No.: 13,571 |
How would i redirect when using Php? At the very beginning of your script, adding the following codes: CODE <?php
header("location:somepage.php"); ?> |
|
|
|
Aug 9 2008, 03:25 AM
Post
#8
|
|
|
A computer once beat me at chess, but it was no match for me at kick boxing. ![]() Group: [MODERATOR] Posts: 4,071 Joined: 24-July 05 From: Linix, DOS and Windows…the good, the bad and the ugly Member No.: 9,787 ![]() |
see the posts above yours.
|
|
|
|
Aug 9 2008, 10:07 AM
Post
#9
|
|
|
Advanced Member ![]() |