Browse files

Add 400 and 403 status pages

  • Loading branch information...
1 parent 6b8acbd commit 9eb25e935cb267045ee436e6e7f115c72779fead @mathiasbynens committed Jan 31, 2012
Showing with 34 additions and 9 deletions.
  1. +7 −2 .htaccess
  2. +6 −2 _inc/start.php
  3. +7 −0 _tpl/status400.tpl
  4. +7 −0 _tpl/status403.tpl
  5. +0 −1 _tpl/{404.tpl → status404.tpl}
  6. +7 −4 index.php
View
9 .htaccess
@@ -75,6 +75,10 @@ RewriteRule ^browse/([a-z0-9-]+)/?$ index.php?slug=browseAuthor&author=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
+RewriteRule ^status/([0-9]{3})/?$ index.php?slug=status&action=$1 [L]
+
+RewriteCond %{REQUEST_FILENAME} !-f
+RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(edit|delete)-comment/([0-9]+)/?$ index.php?slug=$1Comment&id=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
@@ -105,5 +109,6 @@ RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z0-9-]+)? index.php?slug=$1 [L,QSA]
-ErrorDocument 403 /403
-ErrorDocument 404 /404
+ErrorDocument 400 /status/400
+ErrorDocument 403 /status/403
+ErrorDocument 404 /status/404
View
8 _inc/start.php
@@ -76,15 +76,19 @@ function die_magic_quotes_die_die_die(&$value) {
'new',
'search',
'search.atom',
- 'sitemap.xml'
+ 'sitemap.xml',
+ 'status'
);
$reservedActions = array(
'edit',
'delete',
'publish',
'embed',
- 'dev'
+ 'dev',
+ '400',
+ '403',
+ '404'
);
function userAgent() {
View
7 _tpl/status400.tpl
@@ -0,0 +1,7 @@
+<?php
+header('HTTP/1.1 400 Bad Request');
+require('head.tpl');
+?>
+<h1>400 Bad Request</h1>
+<p>The request cannot be fulfilled due to bad syntax.</p>
+<?php $ga = true; require('foot.tpl'); ?>
View
7 _tpl/status403.tpl
@@ -0,0 +1,7 @@
+<?php
+header('HTTP/1.1 403 Forbidden');
+require('head.tpl');
+?>
+<h1>403 Forbidden</h1>
+<p>You don’t have permission to view this document.</p>
+<?php $ga = true; require('foot.tpl'); ?>
View
1 _tpl/404.tpl → _tpl/status404.tpl
@@ -1,5 +1,4 @@
<?php
-$e404 = true;
header('HTTP/1.0 404 Not Found');
require('head.tpl');
?>
View
11 index.php
@@ -32,12 +32,15 @@
$atom = isset($_GET['atom']);
$author = isset($_GET['author']) ? $_GET['author'] : false;
$search = in_array($slug, array('search', 'search.atom')) ? isset($_GET['q']) ? $_GET['q'] : '' : false;
+ $status = $slug == 'status' && $action && is_numeric($action);
if (in_array($slug, $reservedSlugs)) {
- if (!$search && !in_array($_SERVER['REQUEST_URI'], array('/' . $slug, '/' . $slug . '.atom', '/browse/' . $author, '/browse/' . $author . '.atom', '/edit-comment/' . $id, '/delete-comment/' . $id))) {
+ if (!$status && !$search && !in_array($_SERVER['REQUEST_URI'], array('/' . $slug, '/' . $slug . '.atom', '/browse/' . $author, '/browse/' . $author . '.atom', '/edit-comment/' . $id, '/delete-comment/' . $id))) {
header('Location: http://' . DOMAIN . '/' . $slug, null, 301);
}
- include($slug . ($atom ? '.atom' : '') . '.tpl');
+ if (!include($slug . ($status ? $action : '') . ($atom ? '.atom' : '') . '.tpl')) {
+ include('status404.tpl');
+ }
return;
} else {
$url = '/' . ($author ? 'browse/' . $author . ($atom ? '.atom' : '') : $slug . ($atom ? '.atom' : ($rev > 1 ? '/' . $rev : '') . ($action ? '/' . $action : '')));
@@ -92,11 +95,11 @@
}
} else {
@mail(ADMIN_EMAIL, '[jsPerf] Test case without tests, lolwat', $slug);
- require('404.tpl');
+ require('status404.tpl');
}
} else {
// Error: slug not found
- require('404.tpl');
+ require('status404.tpl');
}
} else {
require('index.tpl');

0 comments on commit 9eb25e9

Please sign in to comment.