In urls.py
# urls like "articles/2011/tutorial03" or "articles/2011/tutorial03.html"
urlpatterns = patterns('',
(r'articles/(?P<year>(?U)\\d+)/(?P<item>(?U)[^/]+)(?:\\.htm(?:l)?)?/?\$', 'articles.detail'),
)
In template:
<p><a href="/articles/{{ article.year }}/{{ article.id }}">The Article</a></p>
- Regular expression is hard to read.
- Any change of URL means to change some templates.
- Redirect to the prefered URL must developer provide itself.
In bootstrap.php
$router[] = new new Route('articles/<year \d+>/<item>[.htm[l]]', 'Articles:detail');
In template:
<p><a n:href="Articles:detail $article.year, $article.id">The Article</a></p>
- Route mask is easy to read.
- Any change of URL means to change one line in bootstrap.php.
- Redirect to the prefered URL is done automatically.