note 27008 added to ref.apache
| From: | henk_nicolai at REMOVE-THIS at hotmail dot com | Date: | Wed, 20 Nov 2002 10:03:43 +0000 |
| Subject: | note 27008 added to ref.apache | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-39749@lists.php.net to get a copy of this message | ||
My Apache server has a problem when someone enters a URI like: "http://my_server.nl/index.php/". (Note the
extra slash.) The server executes the index.php script anyway, which causes the browser directory
and the current directory used in the script to be different. And therefore my relative links
don't work, and my stylesheet is not loaded. A quick test ("http://www.php.net/manual/en/index.php/")
reveals that also this site has this glitch.
When a client requests a directory without the last slash ("http://www.php.net/manual") the server sends a HTTP
301 (Moved Permanently) response with a redirect to the correct URI ("http://www.php.net/manual/"), and my idea was to do
the same when the user adds a slash too much:
<?php
$req = $_SERVER['REQUEST_URI'];
// Remove rubbish.
$newReq = ereg_replace ('index.php[^?]*', 'index.php', $req);
if (strlen($newReq) < strlen($req)) {
header ('Location: '.$newReq);
header ('HTTP/1.0 301 Moved Permanently');
die; // Don't send any more output.
}
unset($req); unset($newReq);
... (rest of the script) ...
?>
Replace every occurence of 'index.php' with your filename and you're done. Hope it
helps. :-)
(Note: I'm not using fragments in my URI's (like 'index.php#bottom'), and this
code may not do what you want if you are using them.)
--
http://www.php.net/manual/en/ref.apache.php
http://master.php.net/manage/user-notes.php?action=edit+27008
http://master.php.net/manage/user-notes.php?action=delete+27008
http://master.php.net/manage/user-notes.php?action=reject+27008