Jump to content

help with simple redirect in php


annonshay

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/235725-help-with-simple-redirect-in-php/
Share on other sites

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 :)

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

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.