Try a url_for() helper.
Rewrite most URLs in the templates with url_for()