How to configure SEO-friendly URLs without ContentType
Define more SEO-friendly and pretty URLs that do not contain the Content Type of your record. For example /about-us
instead of /page/about-us
, but beware: if two records of a different Content Type have the same slug, you'll never know for sure which one will be visible on the frontend. For instance, if there is /page/about-us
and /entry/about-us
, then there's no way to objectively guarantee which one of the two items will show up on the shortened /about-us
URL.
To configure Bolt to work with the shortened URL, you'll need to modify two files: routes.yaml
and contenttype.yaml
. The configuration depends on whether or not your site is multilingual.
Configure short URLs for a single-language website
- Locate your
config/routes.yaml
file and underneath the line# Place your own routes here, that have a LOWER priority than the default routes
, add the following:content_seo_default: path: /{slugOrId} methods: [GET|POST] defaults: _controller: Bolt\Controller\Frontend\DetailController::record
This will make sure that the URL is properly matched.
- Configure Bolt to use that route internally as well as using the
|link
filter. To do this, addrecord_route: content_seo_default
to all Content Types inconfig/contenttypes.yaml
, for instance:
entries:
name: Entries
singular_name: Entry
record_route: content_seo_default
# the rest of the Content Type definition...
Note: At this time, the auto-generated links will contain ?contentTypeSlug={yourContentType}
appended to them.
Configure short URLs for a multilingual website
- Locate your
config/routes.yaml
file and underneath the line# Place your own routes here, that have a LOWER priority than the default routes
, add the following:content_seo: path: /{_locale}/{slugOrId} methods: [GET|POST] defaults: _controller: Bolt\Controller\Frontend\DetailController::record
This will match localized URLs, like /en/about-us
and /nl-over-ons
. You can also enable a short URL without the locale for your default locale, by adding a second route underneath:
content_seo_default:
path: /{slugOrId}
methods: [GET|POST]
defaults:
_controller: Bolt\Controller\Frontend\DetailController::record
- Configure Bolt to use that route internally as well as using the
|link
filter. To do this, addrecord_route: content_seo_default
to all Content Types inconfig/contenttypes.yaml
, for instance:entries: name: Entries singular_name: Entry locales: ['en', 'nl'] record_route: content_seo # the rest of the Content Type definition...