Change permalinks and redirects

Hi Guys,

I’m considering changing the permalink structure from /category/year/month/day/post to just /year/month/day/post for two reasons. Firstly, categories change (or new ones get added) quite regularly on our site and this is awful from an SEO point of view. When we ran wordpress(not headless) the Yoast plugin took care of these changes without any issues. Now, frontity only works with one primary category and we are getting a lot of 404 errors.

Secondly, this article (https://digwp.com/2011/06/dont-use-postname/) claims that there is a performance benefit to not having author, category and tags as the first subdirectory in a post url.

My question is - how can I go about implementing this. I would change the permalinks option from the wordpress backend, but I need to have redirects set up that recognize the old link structure then redirects to the new structure.

Thanks in advance!

Sid

Update: I’m using Vercel, I’m trying to use the redirects feature with little luck. It works, but erratically.

here is the code from the vercel.json file:

"redirects": [ 

      { "source": "/([^\/]+)\/([0-9]{4})\/([0-9]{2})\/([0-9]{2})\/([^\/]+)/", "destination": "/$2/$3/$4/$5" }

    ]

I managed to sort it out using the vercel redirects described above… This thread can be closed.

Hey @swahi, well done on resolving your issue. It would be great if you could share your solution for the benefit of other community members who may encounter this.

Thanks @mburridge - I’d be happy to.

There were two solutions I tried, both work. The first is to set up an NGINX reverse proxy (asuming you’re running your own node server) and use a rewrite patter like this:

rewrite "^/([^/]+)/([0-9]{4})/([0-9]{2})/([0-9]{2})/([^/]+)/" https://siteurl/$2/$3/$4/$5 permanent;

The second (since I’m, using Vercel) is to use the vercel.json configuration file to set up redirects

"redirects": [ 

      { "source": "/([^\/]+)\/([0-9]{4})\/([0-9]{2})\/([0-9]{2})\/([^\/]+)/", "destination": "/$2/$3/$4/$5" }

    ]

At the same time, remember to change the permalinks structure in WordPress from /%category%/%year%/%monthnum%/%day%/%postname%/ to /%year%/%monthnum%/%day%/%postname%/

1 Like