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

Link to comment
Share on other sites

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

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.