Add support for aliased URLs or URLs with RewriteBase rules.
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #2943382. -->
Reported by: [cg923](https://www.drupal.org/user/3553687)
>>>
<p>An apology in advance, I am a Drupal newbie, so if I use any incorrect terms or language, please be patient with me.</p>
<p><strong>Problem/Motivation</strong></p>
<p>Items that have had their URLs aliased by a module such as pathauto are not registered as menu entities. For example, while <code>www.example.com/node/1</code> when passed to Tracker::updateEntity() as <code>node/1</code> will be properly indexed, <code>www.example.com/my-aliased-url</code> when passed to updateEntity() as <code>my-aliased-url</code> will not.</p>
<!--break--><p>In addition, if an .htaccess file contains a RewriteBase rule, the index will fail whether the URL is aliased or not. For example, <code>www.example.com/node/1</code> which, due to a RewriteBase rule, becomes <code>www.example.com/extra/node/1</code> will not be indexed.</p>
<p>This is due, I believe, to rather strict pattern matching rules in /core/lib/Drupal/Core/Routing/RouteProvider.php's <code>getRoutesByPath()</code> which is called via several intermediary functions from /src/Tracker.php line 444:<br>
<code>$route_request = $this->getRequestForPath('/' . $path);</code></p>
<p><strong>Proposed resolution</strong></p>
<p>Thankfully, calling <code>getUrlObject()</code> on an entity with an aliased URL will still provide the node id. I have not confirmed other entity types yet, but the node id of an internal URL can be found by calling:<br>
<code>$entity->getUrlObject()->getRouteParameters()['node'];</code></p>
<p>So, for example, a valid path could be built as such in Tracker::updateEntity()</p>
<pre>public function updateEntity(EntityInterface $entity) {<br> <br> ...<br><br> // Get a route match object for the target path of the menu link, so that we<br> // can get a parameter bag.<br> try {<br> // OLD CODE<br> //$path = trim($entity->getUrlObject()->toString(), '/');<br><br> // NEW CODE<br> // Note: External URLs will not have this information.<br> if (!$entity->getUrlObject()->isExternal()) {<br> if ($entity->getUrlObject()->getRouteParameters()['node']) {<br> $path = 'node/' . $entity->getUrlObject()->getRouteParameters()['node'];<br> } <br> }<br> }<br> catch (\InvalidArgumentException $e) {<br> return;<br> }<br> <br> ...<br><br> }</pre><p><strong>Remaining tasks</strong></p>
<p>If a user were tracking more than just content, then getting the "node" parameter and building the $path variable from there obviously does not suffice. Also, if the user has created custom entity types then there would need to be some way of knowing the correct path structure for that custom entity.</p>
<p><strong>User interface changes</strong></p>
<p>-</p>
<p><strong>API changes</strong></p>
<p>-</p>
<p><strong>Data model changes</strong></p>
<p>-</p>
issue