Permalink
Browse files

Fix 404s

  • Loading branch information...
1 parent c47f42c commit 93fcec6730361cc33cff2c50d387d132debd1b71 @gkoberger committed Mar 29, 2012
Showing with 14 additions and 3 deletions.
  1. +14 −3 app-base/404.php
View
@@ -1,9 +1,20 @@
<?php
+function url_exists($url) {
+ $ch = @curl_init($url);
+ @curl_setopt($ch, CURLOPT_HEADER, TRUE);
+ @curl_setopt($ch, CURLOPT_NOBODY, TRUE);
+ @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
+ @curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
+ $status = array();
+ preg_match('/HTTP\/.* ([0-9]+) .*/', @curl_exec($ch) , $status);
+ return ($status[1] == 200);
+}
+
// This script is going to check to see this page exists on p.gko.net
-if(file_exists('../../p.gkoberger.net' . $_SERVER["REDIRECT_SCRIPT_URL"])) {
- Header( "HTTP/1.1 301 Moved Permanently" );
- Header( "Location: http://www.p.gkoberger.net" . $_SERVER["REDIRECT_SCRIPT_URL"]);
+if(url_exists('http://p.gkoberger.net' . $_SERVER["REDIRECT_SCRIPT_URL"]) || url_exists('http://p.gkoberger.net' . $_SERVER["REDIRECT_SCRIPT_URL"] . '/')) {
+ Header( "HTTP/1.1 301 Moved Permanently" );
+ Header( "Location: http://www.p.gkoberger.net" . $_SERVER["REDIRECT_SCRIPT_URL"]);
}
$filename = "p404.html";

0 comments on commit 93fcec6

Please sign in to comment.