I'm porting a site from EE and I'm running into an issue with an existing URL structure not working using routes.

Existing URL Structure: /articles/[year]/[month]/[day]/

I tried creating a route for the above to the articles/index template but it seems no matter what I try I'm returned the 404 page.

Because of the nature of the site, we need users to be routed to the articles/index template no matter what the three child slugs are and then we can display appropriate messaging if an article doesn't exist for the specific date/URL.


It would appear this must be user error as now the expected outcome is working correctly.

Route: articles/[year]/[month]/[day]

Is properly routing users to the articles/index template whether or not an entry exists.


When you create a route, the slugs that you use ('year', ' month', 'day') will be made available in your templates as variables. You will need to use these to retrieve the entry(ies) your looking for. Something like:

Update: Sorry, first version had major errors, should be better now.

{% set datetime = year ~ '-' ~ month ~ '-' ~ day %}
{% set entries = craft.entries.section('articles').postDate('and', '>= ' ~ datetime, '< ' ~ datetime|date_modify('+1 day')) %}

{% if entries %}

    {% for entry in entries %}
            <h1>{{ entry.title }}</h1>
            {{ entry.body }}
    {% endfor %}    

{% else %}
        <p>There are no entries for this date.<p>
{% endif %}

Untested, but should be close. See this question for another example.

| improve this answer | |

Your Answer

