Log in

View Full Version : About 301 Redirect


FatalBreeze
07-18-2007, 08:48 PM
Hello!
I'm considering to buy a new domain name for my website, the existing domain is atraf-f.net and i want to buy atraf-f.com (for example).
But in still want the keep the old domain, so that when someone enters atraf-f.net/forumdisplay.php?f=15 he will be redirected to atraf-f.com/forumdisplay.php?f=15.

I've built a tiny code, and i want to know whether it would work or not, can you tell me please?


if(stristr($_SERVER['SERVER_NAME'],"net")) {
$dir = $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
$dir = str_replace("net","com",$dir);
$dir = "http://".$dir;
header('HTTP/1.1 301 Moved Permanently');
header("Location:$dir");
}


the code will be placed in global_start.

Will it work? Thanks!

c'mon? surely someone must know this...

Dismounted
07-20-2007, 11:41 AM
You should use .htaccess for this instead. There are plenty of tutorials to do this.

FatalBreeze
07-22-2007, 12:54 PM
can you give me a link to a tutorial?

Thanks id advance.

Dismounted
07-23-2007, 06:22 AM
I'll just do it for you...
RewriteEngine On
RewriteCond %{HTTP_HOST} !atraf-f.net$ [NC]
RewriteRule ^(.*)$ http://www.atraf-f.com/$1 [L, R=301]