Clean Urls with Pelican

Posted by Mike Barkas on Saturday January 02, 2016

Creating Custom Urls

Having well crafted urls is important to any site. Making your url structure consistent may help your site visitors understand where they are throughout your blog or site.

With Pelican you can create custom urls for your articles, pages, tags, and so on. Pretty much all your content can have specific url configurations.

The first step to creating custom urls is to configure how Pelican saves your content files. This is usually done in your file.

Articles example:

The two important settings are ARTICLE_URL and ARTICLE_SAVE_AS for how your content is saved and displayed.

ARTICLE_SAVE_AS = '{date:%Y}/{slug}/index.html'
ARTICLE_URL = '{date:%Y}/{slug}'

These settings will save your content file in a directory of year then in a directory created by your slug. The file will have a name of index.html. The directory named after your slug is what allows for clean urls without a file name in your address bar. When this page is requested, the index file is served.

The result of the above settings:

You can customize the url as you like including different year, month, directory, and slug. There is no limit to what you can create.

The key to hiding the file name in the address bar is to use your slug to create a directory and name your file index.html. And your index file will be served but not shown in the url of the browser's address bar.

tags: pelican