Answers.Body: <p>The <a href="https://github.com/craftcms/cms/blob/develop/src/web/UrlManager.php#L378-L413" rel="nofollow noreferrer"><code>UrlManager::_getMatchedElementRoute()</code></a> method does it something like this:</p>
  <pre class="lang-php prettyprint-override"><code>$path = Craft::$app-&gt;getRequest()-&gt;getPathInfo();
  $sitedId = Craft::$app-&gt;getSites()-&gt;getCurrentSite()-&gt;id;
  
  if ($path !== Element::HOMEPAGE_URI) {
      $element = Craft::$app-&gt;getElements()-&gt;getElementByUri($path, $siteId, true);
  }
  </code></pre>
  <p>The logic for determining the element can be found in <a href="https://github.com/craftcms/cms/blob/d7874eb87269cf995ed5a72a7ccb5c0851c41b7e/src/services/Elements.php#L838-L886" rel="nofollow noreferrer"><code>Elements::getElementByUri</code></a>.</p>
  <p>I actually cover some of this in the <a href="https://putyourlightson.com/reading-crafts-source-code#bootstrapping-the-craft-application" rel="nofollow noreferrer">Bootstrapping the Craft Application</a> video of the free <a href="https://putyourlightson.com/reading-crafts-source-code" rel="nofollow noreferrer">Reading Craft's Source Code</a> series, which in my biased opinion is well worth a watch.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-01-09T10:46:08.870Z
Answers.Text: Thanks Ben! I already watched part of your series, but somehow lost track of it.
Answers.UserDisplayName: Matthias Redl-Mann
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-01-02T16:20:18.220Z
Answers.LastActivityDate: 2023-01-02T16:27:49.470Z
Answers.LastEditDate: 2023-01-02T16:27:49.470Z
Answers.UserDisplayName: Ben Croker
Body: <p>From PHP (Plugin), how can I load a certain entry if only the full URL is provided?
  I can not find Craft's logic in PHP to split the full URL into the site's baseUrl and the entry's URI.</p>
  <p>Please note it's a multisite setup, so my site's baseUrl might look like '<code>@web/whatever</code>'</p>
  <p>Thanks</p>
  
Tags: <plugin-development><entry><services><entry-query>
Title: Entry Query: How to load an entry with the full URL as only criterion
ThreadText: # Entry Query: How to load an entry with the full URL as only criterion
  
  (Asked by: username_0 on 2022-12-19)
  
  From PHP (Plugin), how can I load a certain entry if only the full URL is provided?
  I can not find Craft's logic in PHP to split the full URL into the site's baseUrl and the entry's URI.
  
  Please note it's a multisite setup, so my site's baseUrl might look like '`@web/whatever`'
  
  Thanks
  
  **Tags:** plugin-development, entry, services, entry-query
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2023-01-02. Score: 2 | Accepted answer
  
  The [`UrlManager::_getMatchedElementRoute()`](https://github.com/craftcms/cms/blob/develop/src/web/UrlManager.php#L378-L413) method does it something like this:
  
  ```php
  $path = Craft::$app->getRequest()->getPathInfo();
  $sitedId = Craft::$app->getSites()->getCurrentSite()->id;
  
  if ($path !== Element::HOMEPAGE_URI) {
      $element = Craft::$app->getElements()->getElementByUri($path, $siteId, true);
  }
  
  ```
  
  The logic for determining the element can be found in [`Elements::getElementByUri`](https://github.com/craftcms/cms/blob/d7874eb87269cf995ed5a72a7ccb5c0851c41b7e/src/services/Elements.php#L838-L886).
  
  I actually cover some of this in the [Bootstrapping the Craft Application](https://putyourlightson.com/reading-crafts-source-code#bootstrapping-the-craft-application) video of the free [Reading Craft's Source Code](https://putyourlightson.com/reading-crafts-source-code) series, which in my biased opinion is well worth a watch.
  
  > **Comments:**
  > **username_0**: Thanks Ben! I already watched part of your series, but somehow lost track of it.  
  
  ---
  
  