Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Nginx rewrite rule (or routing) help

Started by Muut Archive 11 years ago · 5 replies · 396 views
11 years ago

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.

11 years ago

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.

11 years ago

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/<wildcard1>/<wildcard2>: /post/<wildcard1>

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

would route to

/post/1

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1326 9 years ago
Archive · by Muut Archive, 9 years ago
2 920 9 years ago
Archive · by Muut Archive, 9 years ago
2 4050 9 years ago
Archive · by Muut Archive, 9 years ago
1 2928 9 years ago
Archive · by Muut Archive, 9 years ago
3 1107 9 years ago