Hide $allowed_actions url segment from a url

4.3:

Question:

Hi,

I have a url:
https://sub.domain.com/segment1/segment2/show/something

segment 1 - page
segment 2 - holder page
show - allowed action on the controller
something - url segment of a DO

I would like to hide segment 3 (show) and make it looks like this:
https://sub.domain.com/segment/segment/something

I tried to archive this via routes.yml but it required a major refactor of the site and it still wasn’t working properly.

Would you go down the .htaccess road and how? Or is there a better way of handling this in the framework?

Thanks in advance!

// Include any relevant code. If you have a lot of code, link to a gist instead.

I literally just figured this out out last night. Revert the changes from your routes.yml (I don’t have one), and add the following to your PageController, and then flush:

// Assuming 'show' is your allowed action
private static $url_handlers = [
    '$ID!' => 'show'
];

Check out URL Patterns and URL Handlers to learn more.

2 Likes

That was AWESOME! Thank you Isaac! Huge help! :smiley:

1 Like