Skip to content

Instantly share code, notes, and snippets.

@renoirb
Last active December 23, 2015 11:39
Show Gist options
  • Save renoirb/6629949 to your computer and use it in GitHub Desktop.
Save renoirb/6629949 to your computer and use it in GitHub Desktop.
Reproduce a file from a github repo. (i.e. Poor man github pages!)
#RewriteEngine On
#RewriteCond ^.*$ [L]
#RewriteRule ^(.*)$ /index.php?f=$1
ErrorDocument 404 /index.php
<?php
$base = 'https://raw.github.com/YOURUSERNAME/PROJECTNAME/master/FOLDERYOUWANT';
$requestUri = $_SERVER['REQUEST_URI'];
$path = $base.(($requestUri == '/')?'/index.html':$requestUri);
$basenameArray = explode('.', basename($path));
$file_handle = file_get_contents($path);
// Reproducing EVERY previous HTTP headers and relaying them from GitHub, except Server
foreach($http_response_header as $k => $v){
if(strstr($v, 'Server') === false){
header($v);
}
}
switch($basenameArray[1]){
case 'js':
header('Content-Type: application/javascript');
break;
case 'html':
header('Content-Type: text/html');
break;
}
echo $file_handle;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment