-
Notifications
You must be signed in to change notification settings - Fork 0
/
404.php
129 lines (99 loc) · 4.26 KB
/
404.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
$uri = $_SERVER['REQUEST_URI'];
$query_start = strpos( $uri, '?' );
$_SERVER['PHP_SELF'] = ( $query_start ) ? substr( $uri, 1, $query_start -1 ) : substr( $uri, 1 );
if (isset($_SERVER['REDIRECT_QUERY_STRING'])) {
parse_str( $_SERVER['REDIRECT_QUERY_STRING'], $_GET );
$_REQUEST = array_merge($_REQUEST, $_GET);
}
require_once( 'AMP/BaseDB.php');
require_once( 'AMP/Content/Redirect/Handler.php' );
$handler = &new AMP_Content_Redirect_Handler( );
$handler->execute( );
/*************** Redirection Page
Displayed when a user queries an AMP website
and no resulting page is returned from the database.
Searches redirect table for matching pages, then sends
the user to search page if no matches are found.*/
/*
$no_search_extensions = array( 'jpeg', 'jpg', 'gif', 'png' );
$extension_start = strrpos( $_SERVER['PHP_SELF'], '.' );
$extension = substr( $_SERVER['PHP_SELF'], $extension_start+1 );
if (array_search($extension, $no_search_extensions) !== FALSE ) {
header( 'Status: ' . $_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found' );
exit;
}
// Check for a custom handler.
$uri = $_SERVER['REQUEST_URI'];
$pos = strpos( $uri, '?' );
$PHP_SELF = $_SERVER['PHP_SELF'] = substr( $uri, 1, ($pos) ? $pos - 1 : strlen( $uri ) - 1 );
require_once("AMP/BaseDB.php");
require_once( 'AMP/Content/Page/Urls.inc.php');
if (isset($_SERVER['REDIRECT_QUERY_STRING'])) {
parse_str( $_SERVER['REDIRECT_QUERY_STRING'], $_GET );
$_REQUEST = array_merge($_REQUEST, $_GET);
}
$customHandler = AMP_LOCAL_PATH . "/custom/" . $_SERVER['PHP_SELF'];
if (file_exists($customHandler)) {
ob_start();
ob_start();
include( $customHandler );
$output = ob_get_clean();
ob_end_clean();
// Set response header to reflect the actual status of our request.
//
// if we made it this far, I'm going to assume that everything is just
// fine. Custom scripts that want to redirect must exit() before reaching
// here.
header( 'Status: ' . $_SERVER['SERVER_PROTOCOL'] . ' 200 OK' );
print $output;
} else {
// We haven't found what we're looking for, so flag a 404 error, and try to
// redirect.
header( 'Status: ' . $_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found' );
$redirected = false;
// Search for something to redirect to, based on our redirect table.
$myURI = $dbcon->qstr(substr($_SERVER['REQUEST_URI'], 1));
if ($exactmatches=$dbcon->GetRow("SELECT * FROM redirect WHERE publish=1 AND old=$myURI")) {
$redirected = error_redirect($exactmatches['old'], $exactmatches['new']);
}
if ($conditional_matches = $dbcon->GetRow("SELECT * FROM redirect WHERE publish=1 and $myURI LIKE CONCAT(old, '%') and conditional=1")) {
if (!$redirected) {
$redirected = error_redirect($conditional_matches['old'], $conditional_matches['new'], $conditional_matches['num']);
}
}
$extension_start = strrpos( $_SERVER['PHP_SELF'], '.' );
$extension = substr( $_SERVER['PHP_SELF'], $extension_start+1 );
if (array_search($extension, $no_search_extensions) === FALSE ) {
if (!$redirected) {
if ( strpos( AMP_CONTENT_URL_404, 'http' ) !== false ) {
ampredirect( AMP_CONTENT_URL_404 );
} else {
ampredirect (AMP_SITE_URL . AMP_CONTENT_URL_404 );
}
}
}
trigger_error( 'Requested resource missing: '.$_SERVER['REQUEST_URI'] );
}
function error_redirect( $requested_uri, $target_uri, $num = null ) {
// This is very confusing, and I'm not entirely clear on what it's supposed
// to do or accomplish. Oh well...
$fetch_str = stristr($_SERVER['REQUEST_URI'], $requested_uri);
$fetch_val = ( isset($num) && $num ) ? substr( $fetch_str, $num ) : "";
// Check to see if our REQUEST_URI matches in any way the $requested_uri
if ($fetch_str) {
// Add the appropriate junk if $target isn't a real URI.
if (substr($target_uri, 0, 4) == "http") {
$redirect_uri = $target_uri . $fetch_val;
} else {
$redirect_uri = $GLOBALS['Web_url'] . $target_uri . $fetch_val;
}
// Everything worked out OK. Redirect and report success.
ampredirect( $redirect_uri );
return true;
}
// We didn't redirect, report failure.
return false;
}
*/
?>