Commit b7b80d6d authored by Taylor Otwell's avatar Taylor Otwell

the application url will now be auto-detected.

parent 0897bb43
...@@ -11,7 +11,7 @@ return array( ...@@ -11,7 +11,7 @@ return array(
| |
*/ */
'url' => 'http://localhost', 'url' => '',
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
......
...@@ -34,7 +34,7 @@ class URI { ...@@ -34,7 +34,7 @@ class URI {
// Remove the root application URL from the request URI. If the application // Remove the root application URL from the request URI. If the application
// is nested within a sub-directory of the web document root, this will get // is nested within a sub-directory of the web document root, this will get
// rid of all of the the sub-directories from the request URI. // rid of all of the the sub-directories from the request URI.
$uri = static::remove($uri, parse_url(Config::$items['application']['url'], PHP_URL_PATH)); $uri = static::remove($uri, parse_url(URL::base(), PHP_URL_PATH));
if (($index = '/'.Config::$items['application']['index']) !== '/') if (($index = '/'.Config::$items['application']['index']) !== '/')
{ {
......
...@@ -2,6 +2,35 @@ ...@@ -2,6 +2,35 @@
class URL { class URL {
/**
* Get the base URL of the application.
*
* If the application URL is set in the application configuration file, that
* URL will be returned. Otherwise, the URL will be guessed based on the
* server variables available to the script in the $_SERVER array.
*
* @return string
*/
public static function base()
{
if (($base = Config::$items['application']['url']) !== '') return $base;
if (isset($_SERVER['HTTP_HOST']))
{
$protocol = (Request::secure()) ? 'https://' : 'http://';
// By removing the basename of the script, we should be left with the path
// in which the framework is installed. For example, if the framework is
// installed to http://localhost/laravel/public, the path we'll get from
// from this statement will be "/laravel/public".
$path = str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
return rtrim($protocol.$_SERVER['HTTP_HOST'].$path, '/');
}
return 'http://localhost';
}
/** /**
* Generate an application URL. * Generate an application URL.
* *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment