note 44234 added to function.header

From: Date: Mon, 19 Jul 2004 07:50:46 +0000
Subject: note 44234 added to function.header
Groups: php.notes 
Request: Send a blank email to php-notes+get-73590@lists.php.net to get a copy of this message
On one of my webpages, I often use <base href="..."> to simplify management of intra-site links. This works fine in almost all cases, but some very old browsers, and more importantly, nearly *all* search crawlers don't honor the base href. This often leads to "doubled" URLs such as "/home/home/foo" instead of "/home/foo". Here's a little script to rewrite the former into the latter, intended to be used as your server's 404 error page. <?php $redirect = 'http://'; $redirect .= $_SERVER['HTTP_HOST']; if (preg_match('#(.*/([-A-Za-z0-9$_.+!*\'(),]+))/\2(/.*)#', $_SERVER['REQUEST_URI'], $matches)) { $redirect .= $matches[1]; $redirect .= $matches[3]; header("Location: $redirect"); header("Status: 301 Moved Permanently"); } else { $redirect .= dirname($_SERVER['SCRIPT_NAME']); $redirect .= '/404.html'; header("Status: 404 Not Found"); @readfile($redirect); } ?> ---- Manual Page -- http://www.php.net/manual/en/function.header.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+44234 Delete -- http://master.php.net/manage/user-notes.php?action=delete+44234&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+44234&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#73590) next »