phpretard Posted March 20, 2009 Share Posted March 20, 2009 I am trying to simulate a default 404 for all sites on my server. I need to parse the referring page and redirect to the home page of the applicable site. Here's what I have so far... <?php $url=$_SERVER['HTTP_REFERER']; //$url = 'https://www.dontmatter.com/index.php?limitstart=3 '; // this was for testing print_r(parse_url($url)); echo parse_url($url, PHP_URL_PATH); $404F=$???; // I am trying to get the [host] value from this array and put it in a var. header( "Location: $404F" ) ; ?> Thank you PS. this is just a band aid until I figure out Plesk Link to comment https://forums.phpfreaks.com/topic/150296-solved-parse-url-and-redirect/ Share on other sites More sharing options...
phpretard Posted March 20, 2009 Author Share Posted March 20, 2009 How can I Get "www.dontmatter.com" out of the array and into a variable. Array ( [scheme] => https [host] => www.dontmatter.com [path] => /index.php [query] => limitstart=3 ) /index.php Link to comment https://forums.phpfreaks.com/topic/150296-solved-parse-url-and-redirect/#findComment-789348 Share on other sites More sharing options...
phpretard Posted March 20, 2009 Author Share Posted March 20, 2009 Is this a tough question? I thought it would be easy (for someone)... Link to comment https://forums.phpfreaks.com/topic/150296-solved-parse-url-and-redirect/#findComment-789365 Share on other sites More sharing options...
phant0m Posted March 20, 2009 Share Posted March 20, 2009 yes, it is easy <?php $host = parse_url($url); $host = $host['host']; header("Location: $host"); ?> I suggest you to do some reading about arrays Link to comment https://forums.phpfreaks.com/topic/150296-solved-parse-url-and-redirect/#findComment-789368 Share on other sites More sharing options...
redarrow Posted March 20, 2009 Share Posted March 20, 2009 <?php $url=array("scheme"=>array("host"=>"www.dontmatter.com") ,"path"=>array("/index.php"),"query"=>array("limitstart=3")); $the_url=$url['scheme']['host']; echo $the_url; ?> Link to comment https://forums.phpfreaks.com/topic/150296-solved-parse-url-and-redirect/#findComment-789384 Share on other sites More sharing options...
phant0m Posted March 20, 2009 Share Posted March 20, 2009 <?php $url=array("scheme"=>array("host"=>"www.dontmatter.com") ,"path"=>array("/index.php"),"query"=>array("limitstart=3")); ?> This is not, what parse_url returns. It returns a (one-dimensional) associative. "scheme" is the key, which contains the protocol(eg.g http, https), it is not an array Link to comment https://forums.phpfreaks.com/topic/150296-solved-parse-url-and-redirect/#findComment-789387 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.