From 293427308637b35ec7ceb0b32f26e535eb851d36 Mon Sep 17 00:00:00 2001 From: printempw Date: Mon, 8 Aug 2016 17:49:47 +0800 Subject: [PATCH] redirect /api/textures request to real location --- app/Controllers/TextureController.php | 5 +++++ app/Services/Http.php | 19 +++++++++++++++++-- config/routes.php | 2 ++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/app/Controllers/TextureController.php b/app/Controllers/TextureController.php index 220c1dfb..34bfe6f2 100644 --- a/app/Controllers/TextureController.php +++ b/app/Controllers/TextureController.php @@ -118,6 +118,11 @@ class TextureController extends BaseController } + public static function redirectTextures($api, $hash) + { + Http::redirectPermanently('../../textures/'.$hash); + } + private function checkCache($player_name) { // Cache friendly diff --git a/app/Services/Http.php b/app/Services/Http.php index 753fbb0f..5b11ad9a 100644 --- a/app/Services/Http.php +++ b/app/Services/Http.php @@ -7,8 +7,10 @@ class Http /** * HTTP redirect * - * @param string $url - * @return null + * @param string $url + * @param string $msg Write message to session + * @param boolean $use_js Use javascript to redirect + * @return void */ public static function redirect($url, $msg = "", $use_js = false) { @@ -21,6 +23,19 @@ class Http exit; } + /** + * 301 Moved Permanently + * + * @param string $url + * @return void + */ + public static function redirectPermanently($url) + { + http_response_code(301); + header('Location: '.$url); + exit; + } + public static function getRealIP() { if (!empty($_SERVER['HTTP_CLIENT_IP'])) { diff --git a/config/routes.php b/config/routes.php index ba11137d..4b17ab5c 100644 --- a/config/routes.php +++ b/config/routes.php @@ -129,6 +129,8 @@ Route::group(['middleware' => 'App\Middlewares\CheckPlayerExis } }); +Route::get('/{api}/textures/{hash}', 'TextureController@redirectTextures'); + Route::get('/avatar/{base64_email}.png', 'TextureController@avatar'); Route::get('/avatar/{size}/{base64_email}.png', 'TextureController@avatarWithSize')->where(['base64_email' => '[^\\/]+?']);