Ticket #124 (closed defect: fixed)
404 Error
| Reported by: | kr0n@… | Owned by: | kimparsell |
|---|---|---|---|
| Priority: | high | Milestone: | 1.0 |
| Component: | General | Version: | 1.0b3 |
| Severity: | normal | Keywords: | 2nd-opinion |
| Cc: | mike@… |
Description
I know I can be a little tedious, sorry for that ;)
I realized that Plogger seems to doesn't have a 404 error. Instead of that, if you mis-typed an URL or simply goes to some inexistant album, Plogger redirects you without warning it to the parent correct address.
E.g If you go to
/plogger/true_collection_name/fake_album_name
Plogger will redirect you to
/plogger/true_collection_name/
but the address appearing in your browser will still be the first one!!
I don't find this good for the user experience for diverse reasons, mainly usability and user confusion about this. IMHO the proper action to do here would be show an user-friendly 404 error, maybe with some useful links to redirect the user. But never show a web that wasn't requested and without noticing (even in the browser address bar!)
Well, that's the explanation. My implementation follows now ;) :
1) In the resolve_path() function I modify the following:
// no such collection, return
if (empty($collection)) {
header( "Status: 404 Not Found" );
header($_SERVER['SERVER_PROTOCOL']." 404 Not Found");
return -1;
}
This piece of code is repeated in each if, for collection, album and image level.
2) As you may notice, in case of 404 error the resolve_path() function returns -1, instead of an array as expected. So the next point is to treat this scenario. In the gallery.php I added this:
[...]
// the followling line calculates the path in the album and excludes any subdirectories if
// Plogger is installed in one
$path = join("/",array_diff(explode("/",$_SERVER["REQUEST_URI"]),explode("/",$_SERVER["PHP_SELF"])));
$resolved_path = resolve_path($path);
/*ADDED: No collection, album or image found. Bad url, redirect to 404*/
if ($resolved_path==-1) {
$_GET["level"] = "BADURL";
} else if (is_array($resolved_path)) {
$_GET["level"] = $resolved_path["level"];
$_GET["id"] = $resolved_path["id"];
[...]
and in the the_gallery() function:
[...]
$level = isset($_GET["level"]) ? $_GET["level"] : '';
/*ADDED: No collection, album or image found. Bad url, redirect to 404*/
if ($level=="BADURL") {
putenv("REDIRECT_STATUS=404");
/* ... treat properly the 404 error.
In mine, I used the REDIRECT_STATUS enviroment variable,
that is the reason of the previous line.
Yours may differ, of course */
}
$allowed_levels = array('collection','album','picture','slideshow','search');
[...]
That's all. I'm still testing it, so probably some retouch may be needed ;)
