Simple PHP Custom RedirectionSimple PHP Custom Redirection

I wanted to post this simple tutorial on how to make simple redirection without mysql. With .htaccess you can make the url more simpler so it look more SEO. Let's Start, It won't take long! Approx. time: 1 min.

First create a file named redirect.php;


in redirect.php

Code

<?php
/**** Open PHP Tag then identify your variables**/
 
$aff=$_GET['n'];
 
/***  URL will be in this format http://yoursite.com/redirect.php?<b>n</b>=p2l  so we GET n from URL**/
 
 
/***  let say my url is  http://yoursite.com/redirect.php?<b>n</b>=myfriend  it will redirect to http://myfriendsite.com**/
 
 
if($aff=="myfriend") {
 
 
header('Location: http://myfriendsite.com');
 
}
 
elseif(
$aff=="google") {
 
 
header('Location: http://www.google.com');
 
}
 
 
else {
 
 
header('Location: http://mysite.com');
 
}
 
 
/***  you  can do 100000's of elseif **/
 
 
/***  close PHP**/
 
?>


open notepad and name a new file ".htaccess"

in .htaccess; EDITED ==> This only code will direct all of your tags!


Code

RewriteEngine On
 
 
RewriteRule ^go/([0-9a-z]*)/?$ /redirect.php?n= [NC,L] 


Now the coding part is done. WITH the .htaccess you can redirect in this format http://mysite.com/go/google will redirect you to google or if your server don't support .htaccess your url will be like this: http://mysite.com/redirect.php?n=google will do the same thing.


It's not that hard, Probably The Simplest tutorial there.



StatisticsTutorial Statistics
Date Added: 31-07-2008
Votes: 9
Rating: 8.7
Views: 246

Author: photoshoper

Main Category:
PHP Coding
Sub-Category:
General Development


Rate:
  • Currently 8.7/10 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Sponser Sponser