annonshay Posted May 6, 2011 Share Posted May 6, 2011 Hi, Could someone please help me set up an easy redirect for my wordpress blog? I have 4 domains, I just want them to all redirect to the right place and I don't know how to do it. I'm still learning PHP so I don't know how to write it from scratch yet. "prattandco.com" should stay the same, "prattandco.net" should go to prattandco.com, "robertpratt.com" should go to "prattandco.com/page_id=9" and "robertpratt.net" should go to "prattandco.com/page_id=9" too. Thanks very much in advance! Quote Link to comment https://forums.phpfreaks.com/topic/235725-help-with-simple-redirect-in-php/ Share on other sites More sharing options...
incubi1 Posted May 6, 2011 Share Posted May 6, 2011 Post your code, what you have done on it. incubi Quote Link to comment https://forums.phpfreaks.com/topic/235725-help-with-simple-redirect-in-php/#findComment-1211623 Share on other sites More sharing options...
Tenaciousmug Posted May 6, 2011 Share Posted May 6, 2011 <?php header("Location: URLHERE"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/235725-help-with-simple-redirect-in-php/#findComment-1211626 Share on other sites More sharing options...
annonshay Posted May 6, 2011 Author Share Posted May 6, 2011 I've tried this: <? $sname = $_SERVER["HTTP_HOST"]; $sname = strtoupper($sname); if (instr($sname,"PRATTANDCO.COM") != 0) { response.redirect "prattandco.com"; } elseif instr($sname,"PRATTANDCO.NET") <> 0 then; response.redirect "prattandco.com"; } elseif instr($sname,"ROBERTPRATT.COM") <> 0 then; response.redirect "prattandco.com/page_id=9"; } elseif instr($sname,"ROBERTPRATT.NET") <> 0 then; response.redirect "prattandco.com/page_id=9"; } ?> and this: $sname=$_SERVER["SERVER_NAME"]; $sname=strtoupper($sname); if (_instr(0,$sname,"PRATTANDCO.COM",0) != 0) { header("Location: /"); } elseif (_instr(0,$sname,"PRATTANDCO.NET",0) != 0) { header("Location: /"); } elseif (_instr(0,$sname,"ROBERTPRATT.COM",0) != 0) { header("Location: /page_id=9"); } elseif (_instr(0,$sname,"ROBERTPRATT.NET",0) != 0) { header("Location: /page_id=9"); } function _instr($start,$str1,$str2,$mode) { if ($mode) { $str1=strtolower($str1); $str2=strtolower($str2); } $retval=strpos($str1,$str2,$start); return ($retval===false) ? 0 : $retval+1; } And a couple different variations of those but I don't think they're right... I've been pasting them at the top of my wordpress's home page. The second one I think almost worked- it showed that it was looking for the right file in the address bar, but it couldn't find it... I'm trying to convert from ASP, so I apologize for my stupidity Quote Link to comment https://forums.phpfreaks.com/topic/235725-help-with-simple-redirect-in-php/#findComment-1211642 Share on other sites More sharing options...
incubi1 Posted May 6, 2011 Share Posted May 6, 2011 Try changing it to HTTP_HOST like echo $_SERVER['HTTP_HOST'] ; if ($_SERVER['HTTP_HOST'] == "localhost") { header('Location: http://www.google.com/'); } else echo "No"; Quote Link to comment https://forums.phpfreaks.com/topic/235725-help-with-simple-redirect-in-php/#findComment-1211648 Share on other sites More sharing options...
xyph Posted May 6, 2011 Share Posted May 6, 2011 <?php if( stristr($_SERVER['SERVER_NAME'], 'prattandco.net') != FALSE ) header("Location: http://prattandco.com/"); elseif( stristr($_SERVER['SERVER_NAME'], 'robertpratt.com') != FALSE ) header("Location: http://prattandco.com/page_id=9"); // ETC ?> Quote Link to comment https://forums.phpfreaks.com/topic/235725-help-with-simple-redirect-in-php/#findComment-1211652 Share on other sites More sharing options...
annonshay Posted May 6, 2011 Author Share Posted May 6, 2011 It Finally Works! Thank you SO MUCH!!! I feel stupid- I was trying to make it way too complicated... Quote Link to comment https://forums.phpfreaks.com/topic/235725-help-with-simple-redirect-in-php/#findComment-1211656 Share on other sites More sharing options...
incubi1 Posted May 6, 2011 Share Posted May 6, 2011 HTTP_HOST, SERVER_NAME tomato, tomahto Quote Link to comment https://forums.phpfreaks.com/topic/235725-help-with-simple-redirect-in-php/#findComment-1211658 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.