Alex Rivera | Logout

How can I find an application's base url?

Asked 2008-10-06T23:44:48.467
10

I'd like to find the base url of my application, so I can automatically reference other files in my application tree...

So given a file config.php in the base of my application, if a file in a subdirectory includes it, knows what to prefix a url with.

application/config.php
application/admin/something.php
application/css/style.css

So given that http://www.example.com/application/admin/something.php is accessed, I want it to be able to know that the css file is in $approot/css/style.css. In this case, $approot is "/application" but I'd like it to know if the application is installed elsewhere.

I'm not sure if it's possible, many applications (phpMyAdmin, Squirrelmail I think) have to set a config variable to begin with. It would be more user friendly if it just knew.

Edit
Report

1 Answer

0

This works like a charm for me, anywhere I deploy, with or without rewrite rules:

$baseDir = 'http://'.$_SERVER['HTTP_HOST'].(dirname($_SERVER['SCRIPT_NAME']) != '/' ? dirname($_SERVER["SCRIPT_NAME"]).'/' : '/');

answered 2008-10-07T06:19:53.440

Your Answer