Help With PHP redirect Script

  • Flubber
  • Born
  • Born
  • No Avatar
  • Joined: Apr 22, 2005
  • Posts: 4
  • Status: Offline

Post April 22nd, 2005, 11:24 am

Ok, i got this script saved as index.php so i cna redirect to certain pages according to the adress bar. Cos i dont have reseller but i have 5 parked domains.

PHP Code: [ Select ]
<?php
 
 
 
if ($_SERVER['REQUEST_URI'] == "http://www.runeconference.com") {
 
 
 
header('Location: <!-- m --><span class="postlink">http://www.runeconference.com/shaun/'</span><!-- m -->);
 
 
 
} else if ($_SERVER['REQUEST_URI'] == "http://www.jdjokes.com/") {
 
 
 
header('Location: <!-- m --><span class="postlink">http://www.jdjokes.com/jdjokes/'</span><!-- m -->);
 
 
 
}
 
?>
 
 
  1. <?php
  2.  
  3.  
  4.  
  5. if ($_SERVER['REQUEST_URI'] == "http://www.runeconference.com") {
  6.  
  7.  
  8.  
  9. header('Location: <!-- m --><span class="postlink">http://www.runeconference.com/shaun/'</span><!-- m -->);
  10.  
  11.  
  12.  
  13. } else if ($_SERVER['REQUEST_URI'] == "http://www.jdjokes.com/") {
  14.  
  15.  
  16.  
  17. header('Location: <!-- m --><span class="postlink">http://www.jdjokes.com/jdjokes/'</span><!-- m -->);
  18.  
  19.  
  20.  
  21. }
  22.  
  23. ?>
  24.  
  25.  


And yet when i go to http://www.runeconference.com or http://www.jdjokes.com they come up with a blank page.

What am i doing wrong?

Thanks
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post April 22nd, 2005, 11:24 am

  • whatlikesit12345
  • Guru
  • Guru
  • User avatar
  • Joined: Dec 22, 2003
  • Posts: 1215
  • Status: Offline

Post April 22nd, 2005, 1:11 pm

do you mean
PHP Code: [ Select ]
 
$_SERVER['REQUEST_URL']
  1.  
  2. $_SERVER['REQUEST_URL']

not URl
  • Flubber
  • Born
  • Born
  • No Avatar
  • Joined: Apr 22, 2005
  • Posts: 4
  • Status: Offline

Post April 22nd, 2005, 1:13 pm

Both give same response; a blank page.
  • Tchuki
  • Mastermind
  • Mastermind
  • No Avatar
  • Joined: Sep 30, 2004
  • Posts: 1774
  • Loc: Edinburgh
  • Status: Offline

Post April 22nd, 2005, 1:21 pm

PHP Code: [ Select ]
<?php
 
 
 
if ($_SERVER['REQUEST_URL'] == 'http://www.runeconference.com/') {
 
 
 
header("Location: <!-- m --><span class="postlink">http://www.runeconference.com/shaun/</span><!-- m -->");
 
 
 
} else if ($_SERVER['REQUEST_URL'] == 'http://www.jdjokes.com/') {
 
 
 
header("Location: <!-- m --><span class="postlink">http://www.jdjokes.com/jdjokes/</span><!-- m -->");
 
 
 
}
 
?>
  1. <?php
  2.  
  3.  
  4.  
  5. if ($_SERVER['REQUEST_URL'] == 'http://www.runeconference.com/') {
  6.  
  7.  
  8.  
  9. header("Location: <!-- m --><span class="postlink">http://www.runeconference.com/shaun/</span><!-- m -->");
  10.  
  11.  
  12.  
  13. } else if ($_SERVER['REQUEST_URL'] == 'http://www.jdjokes.com/') {
  14.  
  15.  
  16.  
  17. header("Location: <!-- m --><span class="postlink">http://www.jdjokes.com/jdjokes/</span><!-- m -->");
  18.  
  19.  
  20.  
  21. }
  22.  
  23. ?>


Try that.

Also have you tried replacing REQUEST_URL with HTTP_HOST ?
  • Flubber
  • Born
  • Born
  • No Avatar
  • Joined: Apr 22, 2005
  • Posts: 4
  • Status: Offline

Post April 22nd, 2005, 1:25 pm

Tried both suggestions; neither worked. :?
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Joined: May 28, 2003
  • Posts: 23404
  • Loc: Woodbridge VA
  • Status: Offline

Post April 22nd, 2005, 2:06 pm

I don't get it.

Your sites are on:
http://www.flubb.com/shaun/
and
http://www.flubb.com/jdjokes
respectively.

That doesn't match up to what you appear to be trying to do in your code.

And the page comes up blank because the redirects aren't working and it's simply displaying the index.php page which is blank.
"There's no place like 127.0.0.1 except for ::1."
Alexandria Networks. Leader in IT consulting for associations/non-profits, and small to medium sized businesses around the northern Virginia and Washington D.C. metro area.
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Joined: May 28, 2003
  • Posts: 23404
  • Loc: Woodbridge VA
  • Status: Offline

Post April 22nd, 2005, 2:23 pm

I just saw your post over at WebmasterTalk

I think what Ic3CoLd may have been suggesting was:
PHP Code: [ Select ]
<?php
 
 
 
if ($_SERVER['REQUEST_URI'] == "http://www.runeconference.com") {
 
 
 
header('Location: <!-- m --><span class="postlink">http://www.flubb.com/shaun/'</span><!-- m -->);
 
 
 
} else if ($_SERVER['REQUEST_URI'] == "http://www.jdjokes.com/") {
 
 
 
header('Location: <!-- m --><span class="postlink">http://www.flubb.com/jdjokes/'</span><!-- m -->);
 
 
 
}
 
?>
 
 
  1. <?php
  2.  
  3.  
  4.  
  5. if ($_SERVER['REQUEST_URI'] == "http://www.runeconference.com") {
  6.  
  7.  
  8.  
  9. header('Location: <!-- m --><span class="postlink">http://www.flubb.com/shaun/'</span><!-- m -->);
  10.  
  11.  
  12.  
  13. } else if ($_SERVER['REQUEST_URI'] == "http://www.jdjokes.com/") {
  14.  
  15.  
  16.  
  17. header('Location: <!-- m --><span class="postlink">http://www.flubb.com/jdjokes/'</span><!-- m -->);
  18.  
  19.  
  20.  
  21. }
  22.  
  23. ?>
  24.  
  25.  


I'm still not even certain if that works it will do what you want. Are you trying to mask the address URI so that when a user types, http://www.runeconference.com that's what they see in the address bar instead of http://www.flubb.com/shaun?
"There's no place like 127.0.0.1 except for ::1."
Alexandria Networks. Leader in IT consulting for associations/non-profits, and small to medium sized businesses around the northern Virginia and Washington D.C. metro area.
  • Flubber
  • Born
  • Born
  • No Avatar
  • Joined: Apr 22, 2005
  • Posts: 4
  • Status: Offline

Post April 22nd, 2005, 2:45 pm

Ok let me try and explain it better.

I have 5 parked domains on my NON-Reseller hosting. Its impossible to get them to redirect to certain sub-directories as i have asked the support people many a time.
So i need a script to get the url from the address bar and then redirect to a certain page. So this script would be the index page; and then redirect to a sub-directory containing the website requested in the address bar.

Now i have been talking to the admin of WMT and he says just get reseller to make life easier. And now; i probably will.
  • RichB
  • Guru
  • Guru
  • User avatar
  • Joined: May 17, 2003
  • Posts: 1121
  • Loc: Boston
  • Status: Offline

Post April 22nd, 2005, 3:08 pm

REQUEST_URI is only going to hold a forward slash at the topmost directory rather than the whole url. I don't think there is a predefined variable for REQUEST_URL, but perhaps you could make one like this:

PHP Code: [ Select ]
<?php
 
 
 
$url = 'http://' . $_SERVER['$HTTP_HOST'] . $_SERVER['REQUEST_URI'];
 
 
 
if ($url == "http://www.runeconference.com/") {
 
 
 
header('Location: <!-- m --><span class="postlink">http://www.runeconference.com/shaun/'</span><!-- m -->);
 
 
 
} else if ($url == "http://www.jdjokes.com/") {
 
 
 
header('Location: <!-- m --><span class="postlink">http://www.jdjokes.com/jdjokes/'</span><!-- m -->);
 
 
 
}
 
?>
  1. <?php
  2.  
  3.  
  4.  
  5. $url = 'http://' . $_SERVER['$HTTP_HOST'] . $_SERVER['REQUEST_URI'];
  6.  
  7.  
  8.  
  9. if ($url == "http://www.runeconference.com/") {
  10.  
  11.  
  12.  
  13. header('Location: <!-- m --><span class="postlink">http://www.runeconference.com/shaun/'</span><!-- m -->);
  14.  
  15.  
  16.  
  17. } else if ($url == "http://www.jdjokes.com/") {
  18.  
  19.  
  20.  
  21. header('Location: <!-- m --><span class="postlink">http://www.jdjokes.com/jdjokes/'</span><!-- m -->);
  22.  
  23.  
  24.  
  25. }
  26.  
  27. ?>
Free Programming Resources
  • Tdotwire
  • Proficient
  • Proficient
  • User avatar
  • Joined: Jul 18, 2004
  • Posts: 486
  • Loc: Toronto
  • Status: Offline

Post April 24th, 2005, 8:41 am

this is what I have to get the url of my page

PHP Code: [ Select ]
class page
 
{
 
   var $page;
 
   function page()
 
   {
 
        $this->page = "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
 
   }
 
 
 
   function redirect($href)
 
   {
 
       header("location: ".$href);
 
       exit();
 
   }
 
}
  1. class page
  2.  
  3. {
  4.  
  5.    var $page;
  6.  
  7.    function page()
  8.  
  9.    {
  10.  
  11.         $this->page = "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
  12.  
  13.    }
  14.  
  15.  
  16.  
  17.    function redirect($href)
  18.  
  19.    {
  20.  
  21.        header("location: ".$href);
  22.  
  23.        exit();
  24.  
  25.    }
  26.  
  27. }


now if I were to include it into your script

PHP Code: [ Select ]
//At this rate you must have the page class included into your script
 
 
 
$page = new page;
 
if($page->page == "http://www.runeconference.com/")
 
$page->redirect("http://www.runeconference.com/");
 
else
 
$page->redirect("http://www.jdjokes.com/jdjokes/")
 
 
  1. //At this rate you must have the page class included into your script
  2.  
  3.  
  4.  
  5. $page = new page;
  6.  
  7. if($page->page == "http://www.runeconference.com/")
  8.  
  9. $page->redirect("http://www.runeconference.com/");
  10.  
  11. else
  12.  
  13. $page->redirect("http://www.jdjokes.com/jdjokes/")
  14.  
  15.  


and there you go that does the job
  • redmike
  • Born
  • Born
  • User avatar
  • Joined: Sep 11, 2006
  • Posts: 4
  • Loc: philippines
  • Status: Offline

Post September 11th, 2006, 5:25 pm

Flubber wrote:
Both give same response; a blank page.


try this one..

echo "<meta http-equiv="refresh" content="3;url=http://www.freelancerpilipinas.com">\n";


add this to your heading.. hope it works! :wink:
  • Tchuki
  • Mastermind
  • Mastermind
  • No Avatar
  • Joined: Sep 30, 2004
  • Posts: 1774
  • Loc: Edinburgh
  • Status: Offline

Post September 12th, 2006, 6:21 am

Dude, this post is over 1 year old ....
  • redmike
  • Born
  • Born
  • User avatar
  • Joined: Sep 11, 2006
  • Posts: 4
  • Loc: philippines
  • Status: Offline

Post September 24th, 2006, 7:45 am

Enigmatic wrote:
Dude, this post is over 1 year old ....


hahaha, yeah i know... im just trying to help... maybe for the future use....
  • pankaj
  • Born
  • Born
  • No Avatar
  • Joined: May 26, 2009
  • Posts: 1
  • Status: Offline

Post May 26th, 2009, 4:52 am

I know this is an old topic.
Yet this code worked for me
You can test it at your localhost( local apache)
When I enter "http://localhost" I am redirected to "site1"
And when I enter "http://127.0.0.1" I get redirected to "site2"

This gets useful when you probably use shared hosting on an ecnony package which does not allow you to point your root to a different directory. You can name this as index.php and get going!!
Save $2 per month ( as of year 2009) /per domain


<!--?php print $_SERVER["REQUIST_URL"]; ?-->
<?php
$url = $_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"];

if ($url == "localhost/") {
//print $url;
header('Location: http://localhost/site1');

}

else if ($url == "127.0.0.1/") {
//print $url;
header('Location: http://127.0.0.1/site2');

}
?>

Post Information

  • Total Posts in this topic: 14 posts
  • Users browsing this forum: No registered users and 119 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.