mirror of
https://github.com/laravel/laravel.git
synced 2025-02-20 11:53:14 +08:00
the application url will now be auto-detected.
This commit is contained in:
parent
0897bb4379
commit
b7b80d6d49
@ -11,7 +11,7 @@ return array(
|
||||
|
|
||||
*/
|
||||
|
||||
'url' => 'http://localhost',
|
||||
'url' => '',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
@ -34,7 +34,7 @@ class URI {
|
||||
// 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
|
||||
// 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']) !== '/')
|
||||
{
|
||||
|
@ -2,6 +2,35 @@
|
||||
|
||||
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.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user