ExpressionEngine 2

Back to this add-on's main page
View Other Add-ons From Isaac Raway


You must be logged in to post.

Multiple routes



Hi, how to setup multiple specific routes?

For example this works:

^(?P<url_title>.+)/*$ = "najam-aparata-isusivanje-vlage/_cijena_embed" kaj="{router_url_title}" 

but this does not:

^najam-aparata-isusivanje-vlage/cijena/(?P<url_title>.+)/*$ = "najam-aparata-isusivanje-vlage/_cijena_embed" kaj="{router_url_title}" 

i need multiple routes like:

^najam-aparata-isusivanje-vlage/cijena(?P<url_title>.+)/*$ = "najam-aparata-isusivanje-vlage/_cijena_embed" kaj="{router_url_title}"
^strojno-isusivanje-vlage/hrvatska/(?P<url_title>.+)/*$ = "strojno-isusivanje-vlage/_hrvatska_embed" kaj1="{router_url_title}"
^strojno-isusivanje-vlage/ponuda/(?P<url_title>.+)/*$ = "strojno-isusivanje-vlage/_ponuda_embed" kaj3="{router_url_title}" 


Because i tried this:

^(?P<url_title>.+)/*$ = "najam-aparata-isusivanje-vlage/_cijena_embed" kaj="{router_url_title}"
^(?P<url_title>.+)/*$ = "strojno-isusivanje-vlage/_hrvatska_embed" kaj1="{router_url_title}"
^(?P<url_title>.+)/*$ = "strojno-isusivanje-vlage/_ponuda_embed" kaj3="{router_url_title}" 

and it does not work.


# 1

Hello, can you please help me with multiple routes.

Thank you.

# 2

Once router matches a URL against one of your regex patterns, it stops processing, and returns the embed that matched against that URL. So if you have three routes that are identical, only the first one will ever match anything. There is no way for Router to know if the URL should be handled by one or the other embed template since your template doesn’t have a way to notify Router if it cannot handle an entry.

So the only way to have multiple embeds handle similar URLs is to differentiate them in some way. It could be something small, for instance, you may be able to use “extensions” on your URLs:

^(?P<url_title>.+)\.cijena/*$ = "najam-aparata-isusivanje-vlage/_cijena_embed" kaj="{router_url_title}"
^(?P<url_title>.+)\.hrvatska/*$ = "strojno-isusivanje-vlage/_hrvatska_embed" kaj1="{router_url_title}"
^(?P<url_title>.+)\.ponuda/*$ = "strojno-isusivanje-vlage/_ponuda_embed" kaj3="{router_url_title}" 

This would match URLs such as:

And send each to the appropriate place. You could also use abbreviations

Of course I don’t know if those abbreviations make any sense but hopefully it will give you some ideas.

Finally, one other method I like as well is that of short prefixes, which only works in some cases and works better if you match entry_id rather than URL Title, but of course this only would work for fairly technical sites.

In this case you would designate one letter to correspond to each type of entry.

Hopefully this helps, let me know if you need other ideas or if none of these work for you at all.

# 3

Hello, thank you for your answer, it did not help me much.

Here below are “normal” full url-s: 

that have to be routed into this: 

I gen get one of them to work, but not all of them.

Can you give me some code example to achieve that?

Thank you.


# 4

As I have tried to explain, unless you can change your URL plans and introduce at least ONE CHARACTER to identify the entry type, what you are asking is not possible. My examples provided several ways that you can use simple methods (extensions, one character, etc.) to differentiate entry types. You must use one of these methods, or you won’t be able to use Router to accomplish what you are trying to do.