Reputation: 44692
I'm making a web app and I'm checking for the presence of a configuration file to determine whether or not to run the installation script. However, since it is a web app, I have no idea at what URL this script will be stored.
Is there any way to redirect a page, either using PHP or HTML, to a relative file?
Thanks in advance!
Upvotes: 1
Views: 1823
Reputation: 1803
You can reconstruct the URL of the currently executing script using the 'SCRIPT_NAME' variable set by mod_php. From there it's just a matter of relative path manipulation to construct the absolute URL of the script you want to redirect to.
<?php
$scheme = $_SERVER['HTTPS'] ? 'https' : 'http';
$host = $_SERVER['HTTP_HOST'];
$basedir = dirname($_SERVER['SCRIPT_NAME']);
header("Location: {$scheme}://{$host}{$basedir}/redirect_target_page.php");
Upvotes: 2
Reputation: 44692
I found that I could just do this:
header('Location: ./install.php')
Upvotes: 1
Reputation: 17579
in PHP you can use header('Location: http://www.example.com/');
but it must be used with full url, not the relative one, so you just need to build full url from your relative url and use header
Upvotes: 0