forked from manuelkiessling/nodebeginner.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
header.php
55 lines (43 loc) · 1.18 KB
/
header.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
<?php
ob_start();
$httpHost = $_SERVER['HTTP_HOST'];
$requestUri = $_SERVER['REQUEST_URI'];
$queryString = $_SERVER['QUERY_STRING'];
if ($httpHost === 'nodebeginner.org') {
$location = 'http://www.nodebeginner.org'.$requestUri;
header('HTTP/1.1 301 Moved Permanently');
header('Location: '.$location);
die();
}
if (substr($requestUri, 0, 11) === '/index.html') {
$location = 'http://'.$httpHost.'/';
if ($queryString !== '') {
$location .= '?'.$queryString;
}
header('HTTP/1.1 301 Moved Permanently');
header('Location: '.$location);
die();
}
$pathinfo = pathinfo($_ENV['SCRIPT_FILENAME']);
$extension = $pathinfo['extension'];
if ($extension != 'html') {
header('Cache-Control: max-age=604800'); // 1 week
}
if ($extension == 'html') {
header('Content-type: text/html; charset=utf-8');
}
if ($extension == 'css') {
header('Content-type: text/css; charset=utf-8');
}
if ($extension == 'js') {
header('Content-type: text/javascript; charset=utf-8');
}
if ($extension == 'png') {
header('Content-type: image/png');
}
if ($extension == 'jpg') {
header('Content-type: image/jpeg');
}
if ($extension == 'gif') {
header('Content-type: image/gif');
}