<p>You forgot to escape the dot, but otherwise it looks good to me.</p>

<p>You could replace <code>[a-zA-Z0-9._%-]</code> with <code>.</code> 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 <code>.</code>, not the umlauts), as I think it's not the task of a route to restrict you in doing such things.</p>

CC BY-SA 3.0
2014-07-29T16:27:51.727Z
2014-07-29T16:33:35.027Z
2014-07-29T16:33:35.027Z
carlcs
<p>The simplest way to transform <a href="http://buildwithcraft.com/docs/routing#dynamic-routes">dynamic routes</a> into <a href="http://buildwithcraft.com/docs/routing#advanced-routing">advanced routes</a>, is to go to your <code>craft_routes</code> table and copy it out of <code>urlPattern</code>:</p>

<p><strong>Example:</strong></p>

<p>If you have set this in your backend:<br>
<code>news-sort/month/&lt;year&gt;/&lt;month&gt;</code></p>

<p>You'll find this in <code>urlPattern</code>:<br>
<code>news\-sort\/month\/(?P&lt;year&gt;\d{4})\/(?P&lt;month&gt;(?:0?[1-9]|1[012]))</code></p>

<p>Just remove the escaping <code>\</code>, and you've got your regex:<br>
<code>news-sort/month/(?P&lt;year&gt;\d{4})/(?P&lt;month&gt;(?:0?[1-9]|1[012]))</code></p>

CC BY-SA 3.0
2014-07-29T17:41:01.587Z
great idea, I never thought of that!
mjr
CC BY-SA 3.0
2014-07-29T19:48:41.970Z
awesome answer!
Seán O'Grady
CC BY-SA 3.0
2014-07-29T16:39:33.260Z
2014-07-29T16:39:33.260Z
Victor
<p>I want to move some permanent routes from the admin to my routes config file so that they can be version controlled.</p>

<pre><code>in the admin...
news-sort/month/&lt;year&gt;/&lt;month&gt; ....
news-sort/tag/&lt;tag&gt; ....
news-sort/author/&lt;*&gt;
</code></pre>

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

<pre><code>'news-sort/month/(?P&lt;year&gt;\d{4})/(?P&lt;month&gt;\d{2})' =&gt; 'news-sort/index',
'news-sort/tag/(?P&lt;tag&gt;[a-zA-Z0-9._%-]+)' =&gt; 'news-sort/index',
'news-sort/author/(?P&lt;author&gt;[a-zA-Z0-9._%-]+)' =&gt; 'news-sort/index'
</code></pre>

CC BY-SA 3.0
2014-07-29T16:07:55.493Z
Do they work, mjr?
carlcs
CC BY-SA 3.0
2014-07-29T17:42:08.573Z
I tested one and it seems to work ok
mjr
<config><routes>
`routes.php` config example
# `routes.php` config example

(Asked by: username_0 on 2014-07-29)

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// ....
news-sort/tag/ ....
news-sort/author/<*>

Do these look ok, not 100% sure on the variable and regex etc.
'news-sort/month/(?P\d{4})/(?P\d{2})' => 'news-sort/index',
'news-sort/tag/(?P[a-zA-Z0-9._%-]+)' => 'news-sort/index',
'news-sort/author/(?P[a-zA-Z0-9._%-]+)' => 'news-sort/index'

**Tags:** config, routes
> **Comments:**
> **username_1**: Do they work, mjr?  
> **username_0**: I tested one and it seems to work ok  

---

## 2 answers

### Answer by username_2 on 2014-07-29. Score: 9 | Accepted answer

The simplest way to transform [dynamic routes](http://buildwithcraft.com/docs/routing#dynamic-routes) into [advanced routes](http://buildwithcraft.com/docs/routing#advanced-routing), is to go to your `craft_routes` table and copy it out of `urlPattern`:

**Example:**

If you have set this in your backend:  
`news-sort/month//`

You'll find this in `urlPattern`:  
`news\-sort\/month\/(?P\d{4})\/(?P(?:0?[1-9]|1[012]))`

Just remove the escaping `\`, and you've got your regex:  
`news-sort/month/(?P\d{4})/(?P(?:0?[1-9]|1[012]))`

> **Comments:**
> **username_0**: great idea, I never thought of that!  
> **username_3**: awesome answer!  

---

### Answer by username_1 on 2014-07-29. Score: 3

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.


---

