Using WordPress, often we would use custom post type to create some content and then import this content into a page. Meaning the slug created for each post type content is not relevant, we don’t want visitors to access those web pages, so we need a redirect solution.
How to redirect custom post pages to another page?
In this project (my example) we have a custom post type Teams with different team members. All the team members are displayed on a page called Our teams (multiples teams). We don’t want visitors to be able to access each team member’s URL page/slug created by WordPress (no design for it, no link to them inside the website but for SEO we need a fix). The wish is to have a redirect from each individual team custom post page to the main Our team page.
I needed an easy solution for my client. We don’t want to hardcode the rules to redirect to a specific post ID as those might evolve in the future, so a plugin would be the quick win to allow us to edit values in the CMS directly.
And all the websites pages are under pages for page hierarchy reasons. So we don’t want the custom post child pages to redirect to the parent (this could be done via PHP, adding some code in functions.php)
I tried different plugins – no luck
This allows you to have a redirect option on each custom type but you have to manually enter each destination and it’s a bit invasive visually in the editor and very time-consuming if you have lots of posts.
The version pro of this plugin seems like it might do the job as they say “Need wildcard support for matching multiple URLs? Check out the PRO version.” but if we can avoid buying a plugin… and we didn’t need the dashboard tracking all redirects in that project.
Solution: Simple 301 Redirects by BetterLinks
Finally, I got it working with a free plugin https://wordpress.org/plugins/simple-301-redirects/
It supports wildcards rules
Wildcards: It will redirect all files within a directory to the same filename in the redirected directory. To use wildcards, put an asterisk (*) after the folder name that you want to redirect. Example:
- Request: /old-folder/*
- Destination: /new-folder/*
That’s it. Hope this will help and save you some time!