You could use the Rewrite API. Since you have a fixed set of posts you could do the following:
add_action( 'init', 'rewrite_old_slugs' );
function rewrite_old_slugs(){
$post_slugs = array(
'post-1' => 1,
'post-2' => 2
);
foreach( $post_slugs as $slug => $new_id )
add_rewrite_rule( $slug . '?$', 'index.php?p=' . $new_id, 'top' );
}
I’ve created a post_slugs array where the array keys are the old slugs and the array values are the post ids.
If you go this way, you have to go to Settings > Permalinks and hit the update-button, so the rules are active.
This solution works for posts. If you need it for pages, you need to rewrite the URLs to
index.php?page_id=
Related Posts:
- Stop WordPress appending `-2` to the end of my url after i change it
- WordPress Permalinks not working in Apache2 Ubuntu 14.04
- Get current URL (permalink) without /page/{pagenum}/
- Removing the redirect after changing a page’s slug
- How to display a public profile page for registered users with custom slug?
- How does wordpress keep track of post id when post id is not used in permalinks?
- Permalink Issues by Installing WordPress in Subdirectory / Subfolder
- How to add query parameters to all internal links?
- How to make draft posts or posts in review accessible via full url / slug?
- nginx – permalinks with .php in url not working
- Social Media Links on homepage – within posts/post loop
- Nice RSS Feed URLs for each custom post type
- Custom rewrite rules for feeds of custom queries (query_var query strings in URL)?
- removed index.php now all pages 404
- Permalinks all messed up, I am helpless [closed]
- WordPress | Convert #038; to &
- Can’t get rewrite rules working
- permalink changed, now getting 404 for every pages
- How to write correct add_rewrite_rule in WordPress for more than one taxonomy in one rule?
- How to add category to the permalink and breadcrumb?
- Rewrite my default post URL
- Get permalink to page?
- Permalinks not working Apache + CentOS 7
- How can I link a file in admin with a button?
- Remove Dash/Hyphen From WordPress CustomPosttype Permalink
- Auto-create a pretty permalink for a bunch of posts
- Permalinks: Page Not Found
- How to show the homepage on a different url, like site.com/blog instead of site.com?
- Post incorrectly displaying as page
- wp_logout_url redirects to incorrect page because of pagination
- Dynamically create Permalinks for uploaded files?
- how to add rewrite rule to wordpress default post type
- Get new WordPress slug from old wordpress slug
- Moved page (new parent) loads properly using obsolete URI. Why?
- Only default permalink is working mod_rewrite enabled
- Custom Permalinks for Posts only
- How to add a variable as a tag base?
- Is it possible for a custom post type and sub pages of a page with the same slug as the custom post type to share a slug?
- Why is page/2/ not working?
- Removing leading zeros from custom permalink structure
- Integrating wordpress into existing site and setting up htaccess?
- Permalinks stopped working – NO update, mod_rewrite enabled, .htaccess not touched
- Nginx url rewrite rule problem
- Disable date based archives for all categories except one
- Permalink options page corrupts web.config file
- How to rename ‘Tag Base’ with WPeC 3.8?
- Permalink target for recent post
- Permalink Problems
- Make last three words of excerpt a link
- How do I reclaim either deleted pages or their permalinks?
- url rewrite .htaccess extension to permalink
- Permalink of a page that has already been deleted
- How to remove .html from admin
- Retrieve default permalink while using seo friendly URLs in WordPress
- How do I change the permalink structure without getting 404s?
- When I click on a single post my browser goes to about:blank#blocked and the page is white
- WordPress Permalinks problem
- How to get rid of an extra middle part my permalink
- optional parameter in permalink structure
- Get a link to paged() part?
- How Can I Use a Custom AccessFileName?
- xammp server permalink by postname not working
- Blogger To WordPress Permalink Redirection
- get_permalink() gives a certain page link only. how to solve this.?
- replacing post ID by custom post name in url
- Change type of permalinks on TinyMCE link dialogue
- Problem with special character WordPress
- Permalinks and page store
- How to make different urls for some tags pages
- Change pemalink for one single post without redirect
- Strip subcategory base from URL
- rewrite based slug standar post wp
- How to change specific permalink in wordpress site?
- assets aren’t loading on a page but loads on others? slug permalink conflict?
- remove SLASH on single_post but KEEP on categories and parent pages
- Fire a code when permalinks updated
- Change Project permalink to custom URL
- Edit Post Permalink option removed, looking for possible causes
- Site Tagline ended up in permalink
- Got 404 error when changed siteurl via DB in WordPress
- Permalinks don’t update nor link properly
- Getting 400 Bad request Error when trying to open posts after updating to wordpress 5.0
- Why I had to re-save permalink setting after moving my WordPress site to another hosting provider?
- Permalinks custom base to redirect to archive.php
- Pretty Filter URL
- get_permalink to an anchor
- Add URL to selected post in meta box
- Add Custom Pagination Permalink
- Prevent guessing slug
- Pretty permalinks to work for lighttpd webserver?
- Pages included in another page and duplicate content issues for SEO
- Customize category permalinks
- WordPress archive posts returns user to homepage
- URL to an image in a post is changing when permalink is set to custom. Can I avoid this?
- How can i edit all posts slug in bulk keeping WP native redirect?
- Post/page without slug
- permalinks url with woocommerce
- Blog url disappears
- How to make my custom permalink pull up the correct post
- How to Set Both Category and Sub-Category Level at Root. It should also obey post rule as /category/sample-post and /sub-catgeory/sample-post?