URL best practices
URLs are the foundation of the web. Some rules for good URLs…
- Each URL should point to a resource (i.e. a piece of content)
- They should be human-readable
- Clean URLs - URLs should not contain file extensions such as “.html”, we recommend clean URLs made up of human-readable words. Clean URLs are composed of words in lower-case characters separated by dashes “-”.
- They should be hackable, you should be able to remove sections of a URL and get sensible results. For example:
domain.com/2017/category/short-films
displays a list of short films for a 2017 film festivaldomain.com/2017/category
displays a list of all categories in the 2017 film festivaldomain.com/2017
displays a list of all films in the 2017 film festival (or the festival home page)
- They shouldn’t change. If they do, implement sensible redirects.
- URLs that filter and return data must use GET requests. Remember GET requests are indempotent (i.e. no matter how many times you request this URL the same thing happens). You can also bookmark GET requests easily.
- URLs that change data must be POST requests (e.g. add comments to a news article, login)
- Good URL design is worth getting right at the start of a project. Sketch out URL structure and chat to your team members about it.