I'm trying to create custom php function for redirect. Currently I have this. (I've created index.php file with this function for testing)
function redirect($pageName, ...$parameters)
{
$host = filter_input(INPUT_SERVER, 'HTTP_HOST');
$uri = rtrim(dirname(filter_input(INPUT_SERVER, 'PHP_SELF')), '/\\');
foreach ($parameters as $parameter)
$pageName .= "/".$parameter;
header("Location: http://{$host}{$uri}/{$pageName}");
}
Function works as it should but I have little problem.
I need to make this function work dynamically in root folder of web/subfolder of web/subdomain
Web is meant as that index.file right now
- If I have web in root folder of website, function works without any problems. (Function redirect("page") redirects me for example to domain.com/page
- If I have web in subfolder of website, function works again good (Function redirect("page") redirects me for example to domain.com/folder/page)
- If I have web in subdomain(what is practically subfolder on website) there is problem, for example, I'm on subdomain.domain.com . I will use in index.php redirect("page"), the function redirects me to subdomain.domain.com/folderwhereiscontentofsubdomainlocated/page.
I need to make this function working on all 3 options, so If user will place website anywhere, it will work without problems.
I've spent few hours of looking for solution, but I didn't find anything.
Sorry for my little bit bad English, I hope you will understand :) Have a nice day