Go to the menu - Go to the contents

[Site map] You are here --- > Newbies Paradise > Tutorials > Unofficial > Website > PHP & MySQL > Reading a tutorial

Keep your Pagerank thanks to PHP !

Avatar
Author : Leo
Creation : : on 04/21/2008 12:54:53 PM
Last modification: : on 04/22/2008 12:21:51 PM
Rate and comment this tutorial
Print this tutorial
You are about to read a tutorial written by a member of this website. Although the author probably invested every effort to make this tutorial's content correct, we can not guarantee that the information on this page is 100% exact. Please keep this in mind when reading this tutorial. ;o)
Hi everyone ! My name is Leo. This course was originally published on the French version of this website, "Le Site du Zéro". It was written by .iso. I got his authorization to translate it. If there's any mistake, you can send me a PM ;)

Good morning, good afternoon, good evening, and for the geeks, good night. :p If you've got a website, that you're interested in Google's PageRank, you know that more external links you add, lower will be your PageRank. So how to do ? It's easy : you delete the external links ! :p

Are you crazy ? How do you want me to put my partners' links ? :(

Ok, ok, read this course. ;)
Chapter Contents :

Theory

We're going to do it this way :


Is that all ? :o

Yes, it is. :D

We're going to use the PHP function header(). We're going to proceed this way ($final_url is the URL we want to reach) :

Code: PHP
1
2
3
<?php
header('Location:'.$final_url);
?>


Ready ? Let's go !

Minor alterations

First, you're going to have to rewrite your links on this pattern :




Now, let's deal with the redirection part.

The page "out.php"

Here we are. ;)
Now, create a page called out.php in which we're going to insert the redirection code.

Remember : first we transfer the final URL, so we have to test if there is one (logical, isn't it ? :D ).

Code: PHP
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
<?php

if (isset($_GET['url']))
     {
          //if everything is OK
     }
else 
     {
          //sombody tried to access out.php
     }

?>


Reminder : we are using this PHP function : header('Location:'.$final_url) ! So :

Code: PHP
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
<?php

if (isset($_GET['url']))
     {
          $final_url = $_GET['url'];
     }
else 
     {
          $final_url = 'http://www.your_home_page.com';
    }

header('Location:'.$final_url);

?>

Last alteration

If you tried it at home, 2 different things can have happened :


The first case happens when you haven't declared the HTTP protocol. That's why the server is looking for the file "final_url". Anyway, it's useful to redirect the user during a maintenance, for example. :)

But what we want is case n°2. Once again, you can do it two ways :


If you're normal, you must have chosen the second one. We had written that before :

Code: PHP
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
<?php

if (isset($_GET['url']))
     {
          $final_url = $_GET['url'];
     }
else
     {
          $final_url = 'http://www.your_home_page.com';
     }

header('Location:'.$final_url);

?>


We merely add http:// if $final_url hasn't got it :

Code: PHP
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
<?php

if (isset($_GET['url']))
     {
          $final_url = $_GET['url'];
     }
else
     {
          $final_url = 'http://www.your_home_page.com';
     }

$http = strpos($final_url,'http://');

if ($http === false)
     {
          $final_url = 'http://' . $final_url;
     }

header('Location:'.$final_url);

?>


If you want to know more about the strpos() function, you can go there. :)

Now, you know how to use the PHP redirection. Of course, you can use it for other uses, such as, in the administration part of your website, if the user hasn't written the correct password. :whistle:
Author : Leo
Rate and comment this tutorial
Print this tutorial

Change your template | Learn more about NP | Site map | Terms of use | Rules | RSS feed | XHTML 1.0 | CSS 2.0
Powered by Simple IT SARL: Contact us

There is nothing else to read, you have to go up now !

Do you want to be published here? Contact us.

Number of Newbies connected 4 Newbies Connected | SQL requests 8 Requests | Page loading delay 0.0394s (0.0231s)