Created
September 17, 2018 07:25
-
-
Save racztiborzoltan/e6ab85c3b54d7e8bc0d482ec3cee17e0 to your computer and use it in GitHub Desktop.
remove "/public" from url
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// ============================================================================= | |
// remove "/public" from url: | |
// | |
call_user_func(function(){ | |
// bad: | |
// $_SERVER['REQUEST_URI'] /__RELATIVE_PATH_TO_PAGE_ROOT__/public/__PAGE_RELATIVE_URL__ | |
// good: | |
// $_SERVER['REQUEST_URI'] /__RELATIVE_PATH_TO_PAGE_ROOT__/page_relative_url | |
$prefix = (dirname(dirname($_SERVER['SCRIPT_NAME']))); | |
if ($prefix == DIRECTORY_SEPARATOR || $prefix == '/') { | |
$prefix = ''; | |
} | |
$relative_request_uri = preg_replace('#^'.preg_quote($prefix).'#', '', $_SERVER['REQUEST_URI']); | |
if (preg_match('#^/public/#', $relative_request_uri)) { | |
$new_relative_request_uri = $prefix . preg_replace('#^/public#', '', $relative_request_uri); | |
header('Location: ' . $new_relative_request_uri); | |
exit(); | |
} | |
}); | |
// ============================================================================= |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment