New in Symfony 5.1: URI Resolver

Contributed by
Grégoire Pineau
in #35415 and #35667.

The DomCrawler component eases DOM navigation for HTML and XML documents. Most developers use it in the functional tests of their Symfony applications, but you can use it to build a real crawler.

A common need when building a crawler is to turn the links of the HTML contents, which are usually relative, into absolute URLs, to keep crawling the entire site. For example, if the site URL is and the link URL is ../bar?foo=1, the absolute URL is

This transformation is much more complex than it looks because you have to deal with anchors, query string parameters and all kinds of sub paths. The DomCrawler component already contained the logic to resolve these URLs, but in Symfony 5.1 we've extracted it into a new UriResolver class so you can reuse the logic in your applications:

use Symfony\Component\DomCrawler\UriResolver;

$absoluteUrl = UriResolver::resolve('../bar?foo=1', '');
// $absoluteUrl = ''
Help the Symfony project!

As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.


Very helpful, thank you.

Comments are closed.

To ensure that comments stay relevant, they are closed for old posts.