Pathauto can create path aliases for the node page. For example, it can change node/[nid] to project/[nid], where project is the content type. It doesn't change the path for the node edit page, which is still node/[nid]/edit, instead of project/[nid]/edit as I would expect it to be.

How could I set the path alias to project/[nid]/edit for the node edit page in Drupal 8, when the content type is project?

  • Can you describe why you want to change node edit url? because all CRUD operation have some specific route provided by their module. You don't need to alter them. – Yogesh Kushwaha Dec 13 '18 at 7:44
  • Simple answer: you can't (with a module or config, this would require custom coding) – Hudri Dec 13 '18 at 7:55
  • @Hudri – So, actually you can. The question is how. – leymannx Dec 13 '18 at 8:06
  • 1
    Take a look at this tutorial. This adds an alternative path to edit routes, but it does not replace the existing ones – Hudri Dec 13 '18 at 8:20
  • 1
    This is not possible by routing. You need an outbound path processor to make links content type aware, see drupal.stackexchange.com/questions/259326/…, in your case inbound too, see drupal.stackexchange.com/questions/213855/… and finally Global Redirect now merged into Redirect. – 4k4 Dec 14 '18 at 7:48

Use a src/Routing/RouteSubscriber.php file in your module.

namespace Drupal\example\Routing;

use Drupal\Core\Routing\RouteSubscriberBase;
use Symfony\Component\Routing\RouteCollection;

 * Listens to the dynamic route events.
class RouteSubscriber extends RouteSubscriberBase {

   * {@inheritdoc}
  protected function alterRoutes(RouteCollection $collection) {
    if ($route = $collection->get('entity.node.edit_form')) {


Use a example.services.yml file in your module (if the module is named example).

    class: Drupal\example\Routing\RouteSubscriber
      - { name: event_subscriber }


  • 2
    Yes, the proposal works! But it applies to all content types and nodes. Suppose there are two content types: project and investor, could I achieve both 'project/nid/edit' and 'investor/nid/edit' ? Thanks a lot! – Basic Dec 13 '18 at 14:54
  • I spent my morning attempting to figure out how to set the edit path differently for each individual content type. Unfortunately I came up short and compromised on using a single path that all of my content types would use (e.g. "/my_posts/edit/{node}". I'd love to know if anyone else out there knows how to do this. – mrlexington Oct 25 '19 at 16:26
  • What described by @4k4 in his comment is the way I would go for it. – apaderno Jun 10 at 20:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.