What are some best practices for adapting a script to be installed in a subdirectory in PHP?
When adapting a script to be installed in a subdirectory in PHP, it is important to update the base URL references in the code to reflect the new directory structure. This can be done by dynamically generating the base URL using the $_SERVER['HTTP_HOST'] and $_SERVER['REQUEST_URI'] variables. By doing so, the script will be able to correctly reference its assets and links regardless of the installation directory.
$base_url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['REQUEST_URI']);
define('BASE_URL', $base_url);