Skip to content
Permalink
Browse files

URL redirection is working

  • Loading branch information...
mikekasprzak committed May 13, 2017
1 parent 6afb048 commit 30ab54d485e4b2d4ee4c8cb1336311d1756c5f74
Showing with 92 additions and 13 deletions.
  1. +4 −1 public-url.shortener/.htaccess
  2. +70 −2 src/public-url.redirect/main-redirect.php
  3. +18 −10 src/shrub/src/core/core.php
@@ -1,2 +1,5 @@
#RewriteEngine on
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [B,L]

#RewriteRule ^(.*)$ https://ludumdare.com/$1 [R=301,L]
@@ -1,4 +1,72 @@
<?php
@include __DIR__."/../config.php";
const CONFIG_PATH = "../shrub/";
const SHRUB_PATH = "../shrub/src/";
include_once __DIR__."/".CONFIG_PATH."config.php";
require_once __DIR__."/".SHRUB_PATH."api.php";
echo "huh";
json_Begin();
const DOMAIN_REDIRECT_TABLE = [
'url.ludumdare.org' => 'ludumdare.org',
'url.ludumdare.dev' => 'ludumdare.dev',
'url.jammer.work' => 'jammer.work',
'url.jammer.dev' => 'jammer.dev',
'ldj.am' => 'ldjam.com',
'jam.mr' => 'jammer.vg',
];
$action = json_ArgShift();
$node_id = null;
$specific = false;
if ( !$action ) {
json_EmitFatalError_BadRequest('What?', $RESPONSE);
}
// Do Specific Actions
switch ( $action ) {
case 'SPECIAL': //SPECIAL
$specific = true;
$RESPONSE['ham'] = 1;
break; // case 'SPECIAL': //SPECIAL
default:
if ( !isset(DOMAIN_REDIRECT_TABLE[$_SERVER['SERVER_NAME']]) ) {
json_EmitFatalError_BadRequest('Unknown domain mapping: '.$_SERVER['SERVER_NAME'], $RESPONSE);
}
$url = '//'.DOMAIN_REDIRECT_TABLE[$_SERVER['SERVER_NAME']];
// Do a raw ID decode
if ( $action[0] == '$' ) {
$node_id = intval(substr($action, 1));
}
else {
// TODO: munger
$node_id = 0;
}
if ( !$node_id ) {
json_EmitFatalError_BadRequest('Unknown request', $RESPONSE);
}
$paths = node_GetPathById($node_id, 1);
if ( !$paths ) {
json_EmitFatalError_BadRequest('Unable to trace node: '.$node_id, $RESPONSE);
}
$RESPONSE['paths'] = $paths;
$url .= $paths['path'];
$RESPONSE['url'] = $url;
// Redirect
header('Location: '.$url, true, /*301*/307);
die;
break;
};
json_End();
@@ -213,17 +213,25 @@ function core_RemovePathDotsFromArray($arr) {
/// Internal parser for the API request
function _core_GetAPIRequest() {
// If PATH_INFO is set, then Apache figured out our parts for us //
$PATH = '';
// If PATH_INFO is set, then Apache figured out our parts for us
if ( isset($_SERVER['PATH_INFO']) ) {
$ret = ltrim(rtrim(filter_var($_SERVER['PATH_INFO'], FILTER_SANITIZE_URL), '/'), '/');
if ( empty($ret) /*&& $val !== '0'*/ ) {
return [''];
}
else {
return array_values(array_filter(explode('/',$ret), function($val) {
return !((empty($val) && $val !== '0') || ($val[0] === '.'));
}));
}
$PATH = $_SERVER['PATH_INFO'];
}
// Alternatively if REDIRECT_URL is set, then this was a redirect
else if ( isset($_SERVER['REDIRECT_URL']) ) {
$PATH = $_SERVER['REDIRECT_URL'];
}
$ret = ltrim(rtrim(filter_var($PATH, FILTER_SANITIZE_URL), '/'), '/');
if ( empty($ret) /*&& $val !== '0'*/ ) {
return [''];
}
else {
return array_values(array_filter(explode('/', $ret), function($val) {
return !((empty($val) && $val !== '0') || ($val[0] === '.'));
}));
}
// If PATH_INFO isn't set, assume it's the same as '/'

0 comments on commit 30ab54d

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.