Web Hosting Talk







View Full Version : redirect file helps please


DTN
12-02-2005, 03:26 PM
i want to redirect subdomain to certain file such as http://sub.domain.com redirects to http://sub.domain.com/index.php?name=Downloads

thanks

azizny
12-02-2005, 05:40 PM
Since the file is same place... In your index.php in the subdomain do this:

<?php
//This will always redirect to index.php?name=Downloads if and only if you are not passing any other variables by the get
if($_GET == NULL){$_GET[name] == 'Downloads';}

//This will always redirect to index.php?name=Downloads no matter what
$_GET['name'] = 'Downloads';
?>

Peace,

Korvan
12-02-2005, 06:06 PM
Here is the php way to do a redirect.

header('Location: http://sub.domain.com/index.php?name=Downloads');
exit();//end all processing on the page.

DTN
12-03-2005, 12:02 AM
Here is the php way to do a redirect.

header('Location: http://sub.domain.com/index.php?name=Downloads');
exit();//end all processing on the page.


Where should I insert the code Korvan? inside the <head> tag? I've found something really odd that if i redirect to different subdomain then the page runs really fast, except for the same subdomain :-( it takes forever to redirect

Dan L
12-03-2005, 12:48 AM
Put the code between <?php and ?>.. make sure it's before ANY html!

Jeremy2
12-03-2005, 01:34 AM
If you want to use javascript and do it from the client side rather than server side, insert this code:

<javascript language="JavaScript">
<!--
window.location="http://sub.domain.com/index.php?name=Downloads";
//-->
</javascript>

Azavia
12-03-2005, 08:44 AM
However, if you put the PHP code to redirect within index.php of sub.domain.com, it'll loop infinitely. What azizny gave was just fine.