Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to move some permanent routes from the admin to my routes config file so that they can be version controlled.

in the admin...
news-sort/month/<year>/<month> ....
news-sort/tag/<tag> ....

Do these look ok, not 100% sure on the variable and regex etc.

'news-sort/month/(?P<year>\d{4})/(?P<month>\d{2})' => 'news-sort/index',
'news-sort/tag/(?P<tag>[a-zA-Z0-9._%-]+)' => 'news-sort/index',
'news-sort/author/(?P<author>[a-zA-Z0-9._%-]+)' => 'news-sort/index'
share|improve this question
Do they work, mjr? – carlcs Jul 29 '14 at 16:07
I tested one and it seems to work ok – mjr Jul 29 '14 at 17:42
up vote 7 down vote accepted

The simplest way to transform dynamic routes into advanced routes, is to go to your craft_routes table and copy it out of urlPattern:


If you have set this in your backend:

You'll find this in urlPattern:

Just remove the escaping \, and you've got your regex:

share|improve this answer
great idea, I never thought of that! – mjr Jul 29 '14 at 17:41
awesome answer! – Sean O'Grady Jul 29 '14 at 19:48

You forgot to escape the dot, but otherwise it looks good to me.

You could replace [a-zA-Z0-9._%-] with . to allow all characters in the slug. Maybe you want to use german umlauts or other special characters in your slugs at some point (you probably shouldn't, but who knows). I'd do that (the ., not the umlauts), as I think it's not the task of a route to restrict you in doing such things.

share|improve this answer
great, thanks for the tip! – mjr Jul 29 '14 at 17:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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