Hi,
I have a number of template groups that have an index and detail page. The default EE url for the template group is domain.com/blog/post/url_title where ‘blog’ is the template group and ‘post’ is the single entry page.
I have setup a template route to bypass the single entry page so the url is now domain.com/news/url_title
The issue is that other pages return a 404 if I don’t add them as a template route. Is this expected behaviour?
Thanks Wayne.
I have found the cause of my issue. I have a template group called ‘sector’ with an ‘index’ template. This will product the domain structure domain.com/sector/sectorname
I want the url to be domain.com/sectorname so I created a template route to achieve this using /{url_title:regex[(((?!(P\d+|category\/)).)+?)]} as the route.
With this route in place all other pages return 404 unless I add them as template routes.
Is is possible to achieve the result I’m after without adding every page to the template routes?
There is (I think) some way of doing that using the Template Routes system, but for a long time it has been notoriously flaky (particularly if you want to use routes with pagination) and many have concluded that solutions that are perhaps less elegant but more reliable are more useful.
In your example, the simplest solution might be to declare the ‘sector’ template group as your “home” group - then EE will try to match the segment_1
value against a template group with that value, if that’s not found it will look for a template with that value within the sector template group, and if that’s not found try and process the segment using the index template. Which seems to be roughly what you are after.
For this approach to work you would need to do some work to ensure your ‘home’ page template gets loaded when there is no segment_1 value. How you do this depends a bit on how your site is set up, but one solution would be simply put a conditional at the start of your index template and if segment_1
was blank then load the home page template (either by reading it from the index.html template, or perhaps using layout variables to switch processing to the right template), and otherwise (i.e. if segment_1 is not blank and not a template group) load the sector template as you would otherwise.
HTH
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.