bolt / core

🧿 Bolt 5 core
https://boltcms.io
MIT License
539 stars 159 forks source link

Pretty URLs without ContentType #2261

Closed I-Valchev closed 3 years ago

I-Valchev commented 3 years ago

Support "pretty" short URLs without the ContenType for multiple/all ContentTypes, like so:

/pages/about-us -> /about-us
/reviews/john-doe -> /john-doe
/posts/how-to-learn-js -> /how-to-learn-js

Known issues There is a conflict if two records of different ContentTypes have the same slug. However, in most cases this is an edge-case.

To achieve this, the contentTypeSlug in DetailController should be optional. Then in routing we should warn the user of potential slug clash, but allow them to take the risk, if they choose to.

bobdenotter commented 3 years ago

Yes, sounds good! :+1:

peterboorsma commented 3 years ago

MAKE IT SO ;)

simongroenewolt commented 3 years ago

Just a thought that popped into my head: Should this be implemented as:

'all pages, reviews, and posts are accessible without their contentTypeSlug'

or as

'the pages, reviews, and posts contenttypes get an additional check box in the editor to expose them without contentTypeSlug'

or as

'add a feature that works like a symbolic link so you can map a random path to a contentTypeSlug/id'

The last approach is what I'd use to 'manually' fix this if needed for a couple of pages by creating a route in the symfony routes.yaml config, but that would be outside of bolt, and will prevent bolt itself from generating the 'nice' link so you'd have to hard-code the links in your templates.

I think I'd like the option with a check box in the admin editor more that a blanket 'just expose everything' approach, but the downside is it will add an additional setting that you'll have to choose.

peterboorsma commented 3 years ago

I like the second one...

I-Valchev commented 3 years ago

@simongroenewolt in my eyes, ideally it will be something that the implementor (site developer) enables, perhaps for as many or as few Content Types as they like. I am not sure it will be easy to allow editors to do this on a per-record basis, in fact it might be pretty confusing for them.

peterboorsma commented 3 years ago

I reacted to quickly :) I agree with @I-Valchev. I don't want my editors to screw around with urls.

simongroenewolt commented 3 years ago

I understand (sometimes?) not wanting editors to mess with the urls, I just thought that to me this feature looked promising to make for example a nice looking and rememberable /about page along all other 'regular' /page/subject1, /page/subject2, ... etc. Maybe that is a different feature 'though ;-)

I-Valchev commented 3 years ago

Hi @simongroenewolt , in fact you can already make a nice looking /about page, admittedly that's not something the Editor can as it's in routes.yaml.

This sort of borders to another feature I'm eager to see in Bolt one day, namely a nice visual editor for config files such as menu.yaml, config.yaml, routes.yaml (simplified) and/or redirect options.

What might be nice, but this will likely better work as an extension, is to have a page in the backend where Editors can add redirects, or say something like "on a given url {url}, show the contents of {record}" (in a visual way, of course). Then that extension can also add it's widget to edit page routes. 🤔

Just brainstorming some ideas here, don't mind me!

I-Valchev commented 3 years ago

Hi all!

While we are working out a solution, here is an article that explains how to achieve this outcome as of right now: https://bolt.tips/entry/seo-friendly-urls-without-contenttype

bobdenotter commented 3 years ago

Fixed in #2325