Help With PHP redirect Script

  • Flubber
  • Born
  • Born
  • Flubber
  • Posts: 4

Post 3+ Months Ago

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
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • whatlikesit12345
  • Guru
  • Guru
  • User avatar
  • Posts: 1211

Post 3+ Months Ago

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

not URl
  • Flubber
  • Born
  • Born
  • Flubber
  • Posts: 4

Post 3+ Months Ago

Both give same response; a blank page.
  • Tchuki
  • Mastermind
  • Mastermind
  • Tchuki
  • Posts: 1774
  • Loc: Edinburgh

Post 3+ Months Ago

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
  • Flubber
  • Posts: 4

Post 3+ Months Ago

Tried both suggestions; neither worked. :?
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23456
  • Loc: Woodbridge VA

Post 3+ Months Ago

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.
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23456
  • Loc: Woodbridge VA

Post 3+ Months Ago

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?
  • Flubber
  • Born
  • Born
  • Flubber
  • Posts: 4

Post 3+ Months Ago

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
  • Posts: 1121
  • Loc: Boston

Post 3+ Months Ago

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. ?>
  • Tdotwire
  • Proficient
  • Proficient
  • User avatar
  • Posts: 486
  • Loc: Toronto

Post 3+ Months Ago

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
  • Posts: 4
  • Loc: philippines

Post 3+ Months Ago

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
  • Tchuki
  • Posts: 1774
  • Loc: Edinburgh

Post 3+ Months Ago

Dude, this post is over 1 year old ....
  • redmike
  • Born
  • Born
  • User avatar
  • Posts: 4
  • Loc: philippines

Post 3+ Months Ago

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
  • pankaj
  • Posts: 1

Post 3+ Months Ago

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 73 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
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.