File: redirect.php

package info (click to toggle)
moodle 1.6.3-2%2Betch3
  • links: PTS
  • area: main
  • in suites: etch
  • size: 37,172 kB
  • ctags: 51,688
  • sloc: php: 231,916; sql: 5,631; xml: 2,688; sh: 1,185; perl: 638; makefile: 48; pascal: 36
file content (40 lines) | stat: -rw-r--r-- 1,009 bytes parent folder | download | duplicates (3)
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
<?php // $Id: redirect.php,v 1.1 2006/04/11 07:53:59 moodler Exp $

/**
If you're using custompix in your theme, but you don't want to have to copy every pix from /pix into /theme/yourtheme/pix, use this as a 404 handler.
You need to put a snippet like the following into your apacheconfig:

<Location /moodle/theme/yourtheme/pix >
   ErrorDocument 404 /moodle/pix/redirect.php
</Location>

**/


require_once('../config.php');

// obtain the requested path.
if (!array_key_exists('REDIRECT_STATUS',$_SERVER) || $_SERVER['REDIRECT_STATUS'] != 404) {
    die();
}

$matches = array();

if (!preg_match('/theme\/[^\/]*\/pix\/(.*)$/',$_SERVER['REDIRECT_URL'],$matches)) {
    die();
}

if (file_exists($CFG->dirroot.'/pix/'.$matches[1])) {
    header("Location: ".$CFG->wwwroot.'/pix/'.$matches[1]);
}

?>
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head>
<body>
<h1>Picture not found</h1>
<p><?php echo $_SERVER['REDIRECT_ERROR_NOTES']; ?></p>
</body>
</html>