-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredirect-images.php
53 lines (46 loc) · 1.51 KB
/
redirect-images.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
<?php
/**
* redirect old http://wikia/images to http://images/wikia/images
*/
$HeadURL = explode('/', '$HeadURL$');
$wgReleaseNumber = ($HeadURL[4] === "trunk" ) ? "trunk" : $HeadURL[5]; // we generally use wgCacheBuster now instead. can use that here instead of wgReleaseNumber if desired
$wgStylePath = "http://images.wikia.com/common/__cb{$wgReleaseNumber}/skins";
$newUrl = "";
$age = 1200;
$imgUrl = "http://images.wikia.com/";
if( isset( $_GET["skinpath"] ) ) {
$skinPath = $_GET["skinpath"];
$newUrl = $wgStylePath . "/" . $skinPath;
$age = 86000;
}
else {
$imgFile = stripslashes($_GET["image"]);
#--- we take first part of domain name
if (!empty($_SERVER['SERVER_NAME'])) {
$aDomainParts = explode(".", $_SERVER['SERVER_NAME']);
}
/**
* we have two kinds of domains:
* 1) three parts (wikia-name.wikia.com)
* 2) four parts (language.wikia-name.wikia.com)
*
* and ...
*
* 3) others as well but we so far handle only these two with some exceptions
*/
if( $_SERVER['SERVER_NAME'] === "uncyclopedia.org" ) {
$newUrl = $imgUrl . "uncyclopedia/images/" . $imgFile;
}
elseif( count($aDomainParts) == 3 ) {
#--- first part should be wikia name
$newUrl= $imgUrl . $aDomainParts[0] . "/images/" . $imgFile;
}
elseif ( count($aDomainParts) == 4 ) {
#--- first part should be wikia name
$newUrl = "{$imgUrl}{$aDomainParts[1]}/{$aDomainParts[0]}/images/{$imgFile}";
}
}
header("Cache-Control: public, max-age={$age}", true);
header("Location: {$newUrl}", true, 301);
exit(0);