holden43 Posted March 5, 2008 Share Posted March 5, 2008 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 Quote Link to comment Share on other sites More sharing options...
Isityou Posted March 5, 2008 Share Posted March 5, 2008 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); } ?> Quote Link to comment Share on other sites More sharing options...
holden43 Posted March 5, 2008 Author Share Posted March 5, 2008 Thank you very much... I was getting a headache trying to do it the other way. That worked perfectly Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.