Jump to content

PHP two Domains redirect


holden43

Recommended Posts

I have searched google all over for code to do the following

 

My problem: I have 2 domains both of which point to one hosted server and I want each domain to point to a different subdirectory.  for example i want X.com to point to X.com/X/ and Y.com to point to Y.com/Y/    (respectively being /htdocs/X/ and /htdocs/Y/)

 

This is what I did:

 

created redirect.txt with :

 

x.com|www.x.com|x/index.php
y.com|www.y.com|y/index.php

 

redirect.php with:

 

<?
$remote = getenv("HTTP_HOST");
$fp = @fopen("redirect.txt", "r");

while (!feof($fp)):
$line = fgets($fp, 200);
$line_list = explode("|",$line);

$url1 = $line_list[0];
$url2 = $line_list[1];
$redirect = $line_list[2];

if ($url1 == $remote or $url2 == $remote):
Header("Location:$redirect");
fclose($fp);
endif;
endwhile;
fclose($fp);
?>

 

now I am very new to this, and I found the above code from a post made in 2001 for php3, i am running php4.

 

the above solutions works but... it is ungodly slow, it takes about 5 minutes to redirect, can anyone tell me what is causing the slowdown?

 

I would appreciate any suggestions

 

Link to comment
Share on other sites

Just slap headers to redirect in your index files.

 

EDIT: Sorry misread, fixed it up

index.php
<?php
$domain = $_SERVER['HTTP_HOST'];

if($domain == "x.com")
{
    header('Location: x.com/x');
}
else if($domain == "y.com")
{
    header('Location: y.com/y);
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.