Permalink
Browse files

auto-slash 404s

  • Loading branch information...
1 parent df6efc5 commit b019daec240c3345e6fe2f29e5867ae66f584fc6 @iamcal committed Mar 16, 2012
Showing with 21 additions and 0 deletions.
  1. +21 −0 404.php
View
21 404.php
@@ -1,6 +1,27 @@
<?
include('init.php');
+
+ #
+ # try adding a slash at the end if:
+ # 1) we've not already mapped it through a RewriteRule
+ # 2) it doesn't look like a filename
+ # 3) it doesn't already have a slash at the end
+ #
+
+ $url = $_SERVER['REQUEST_URI'];
+ $orig = $_SERVER['REDIRECT_URL'];
+
+ if ($url == $orig){
+ $last_part = array_pop((explode('/', $url)));
+ if (preg_match('!^[^\.]+$!', $last_part)){
+
+ header("location: $url/");
+ exit;
+ }
+ }
+
+
$error = "The page you requested could not be found.";
include('notfound.php');
?>

0 comments on commit b019dae

Please sign in to comment.