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
https://forums.phpfreaks.com/topic/94442-php-two-domains-redirect/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.