You are browsing the unmaintained documentation for old Nette 2.0. See documentation for current Nette.

URL Parser and Builder

Class Nette\Http\Url encapsulates any URLs according to RFC 3986 and allows easy manipulation with their parts.

The following scheme covers individual parts of URL:

scheme  user  password  host  port  basePath   relativeUrl
   |      |      |        |      |    |             |
 /--\   /--\ /------\ /-------\ /--\/--\/----------------------------\
                     |                     |           |         |
                 authority               path        query    fragment

Usage is then very intuitive:

use Nette\Http\Url;

$url = new Url('');

echo $url->absoluteUrl; // or directly echo $url; returns full URL
echo $url->scheme;      // http
echo $url->authority;   //
echo $url->hostUrl;     //
echo $url->path;        // /en/documentation
echo $url->query;       // action=history
echo $url->fragment;    // footer

In addition to http URL scheme, it's possible to use others, for example https, file or ftp.

Parts of an URL can of course be changed.

$url = new Url('');
$url->path = '/';
echo $url; //

The canonicalize() method converts URL to its canonical form.


Class UrlScript is a descendant of Url. It indicates which part of URL is a path to currently running script. It is used inside Nette\Http\Request class.
                       |              |
                  scriptPath       pathInfo