How to Make SEO Friendly URL’s with VAPOR?

First of all you should add new Field to your Model as a string which named ‘slug’.


After that, you should edit your migration. Important thing is, slug shouldn’t be ‘.required’. Otherwise, when you creating new data you have enter your slug manually every request. Also, your field should be unique. This prevents duplicate pages.


As a third step, you should create new file which named ‘String+Ext.swift’ or other name what you wish. Also there is link for copying for code.


Lastly, you should 2 lines for your create function. Let’s say, our model name is ‘Entry’. We should create slug for new entries.


I used title Field for slug. You could use different field for your url’s. Don’t forget to ‘:slug’ parameter to add your routes. Like this:


This is the image that how I am catching slug’s.


Note: I know this is very basic tutorial for slugs but it is better than sharing nothing.

Leave a Reply