Nginx rewrite rule (or routing) help

Hello,

I’m storing my blog posts in numerical sequential order, like primary keys in a RDMS.

user/pages/post/1
user/pages/post/2
etc.

My permalink format is going to be as so: example.com/post/1/title-of-story-1

I want the last portion to not matter though. In the event that I change the titles to any of my blog posts, I still want my old permalinks to work.

I want example.com/post/1/anything-here to route to example.com/post/1

What is the best approach to achieve this? I’m not very familiar with regex and nginx rewrite rules, I’m guessing that’s the way to go about it.

Thanks in advance.

You should be able to do this in Grav with the site.yaml file using a wildcard alias for the routes. See http://learn.getgrav.org/advanced/route-aliases

This is sort of in the realm of custom routing, which at the moment Grav does not support, but could be pretty cool to have in the future.

Thanks for the replies.

@rhukster

It would be great if that could be added. It’s useful in situations where a post title may change or the same title is used often. If routing supported more than 1 wildcard it could be as simple as something like this perhaps?

routes:
/post//: /post/

/post/1/this-is-just-for-a-friendly-looking-url

would route to

/post/1

Please create an issue here: https://github.com/getgrav/grav/issues

I’ll mark it as a feature enhancement so it’s not forgotten!

https://github.com/getgrav/grav/issues/178

Thanks boss! :slight_smile: