Skip to content

How to generate unique urls and pages with template?

I am building a petition site where you can create/join petitions.
I have made a page where there is table filled with many pre-created petition titles and I want to make that when people click on any petiton title, they would get to another page that gets data from my database and fills it by a template(title, description and etc) and generates a unique url with the petition title in it so that people can share it with their friends.

Below is linked a site that represents 100% of that how I want it to work.

For an example this site has this url , but when you click on any petition it redirects you to a specific to this petition url, for an example or .

I am new to coding and I can’t find anything about such action, so any guidance on what is this called and etc. is very welcomed.


  • take the title of the petition
  • remove any non-url safe characters, like / or ?
  • replace any whitespaces with -
  • check if the result is already present in your database
    • no: return the title and save it
    • yes: append a random number to it, save and return