This would be bad practice, since WordPress already has a functionality to do this built in. Rewriting the built in functionality is never a good idea.
To achieve this the best way is to use Taxonomies.
Lets say you create two categories:
- Foo
- Bar
Now select the categories for the post in question and setup your permalinks structure to be /%category%/%postname%/
and you will get:
- foo/post-name
- bar/post-name
Hope this helps.
Related Posts:
- remove “index.php” from permalinks
- Rewrite Rule for Multilingual Website, Like qTranslate?
- Regex in add_rewrite_tag not accepting OR operators?
- How to add a custom URL placeholder to author archives?
- Permalink/Pagination issue: Category base name same as page name
- URL Rewrite + Page + Custom Post Type = Unusual Redirect
- Make post slug have priority over category slug
- Custom Rewrite with Query vars
- flexible rewrite ‘ramble’ URLs with WordPress
- add_rewrite_rule with 3 or fewer matches?
- Permalinks for WooCommerce Categories and Subcategories
- Change the custom post type permalink
- Redirect short-form URL to long-form URL (post_id to post_id + post_name)
- How to change URL structure for pagination pages?
- Rewriting permalinks with custom posts
- Rewrite rule never matching
- Rewrite-Rules not working on a vhost, everything goes to index.php
- Date archive permalink modification
- How to Modify Existing Rewrite Rules?
- rewrite_rule for custom post type doesn’t affect get_permalink
- Add ‘articles’ prefix before blog posts url without affecting pagination
- How to get wordpress link to fully evaluate when coming from facebook
- custom permalink/shortlink with base62 encoded post ID
- Page Attachment Permalink Structure based on Menu Order?
- query_vars in plugin not working?
- WordPress not respecting template hierarchy (fetches index.php instead of single.php or page.php)
- Call to a member function add_rule() on a non-object
- I need a custom permalink for my website
- Why is add_rewrite_endpoint incompatible with /%category%/%postname%/ permalink structure?
- Re-write specific custom post type category URL to go to another page
- How to add_rewrite_rule with two parameters to a single view page?
- Rewrite Rule for default post type
- RewriteRule accepts numbers but not letters in tag
- Custom query var rewriting with only variable
- Date Archives’ Permalinks under Category folder
- Custom Permalink
- remove sub-category of Custom Post Type from permalink structure
- add_rewrite_rule not working for me
- Using WP Rewrite, but just not “getting it”
- Share same Slug for a Custom Post Type and 2 Taxonomies
- How to remove specific category from URL in WordPress
- Rewrite CPT permalinks and include WPML language
- Redirect Uploads Folder to Query Vars in WordPress
- Custom permalink leads to index page
- WordPress add_rewrite_tag working for Posts, but not working for Pages
- Need To Add Custom rewrite base url for individual user
- Rewriting single post url; add_rewrite_rule problem?
- Permalinks only for posts
- rewrite rule to redirect to the most recent date permalink
- How to change “attachment_id” in attachment permarlink?
- How to test custom rewrite rules /permalinks?
- wordpress how to replace url /bar with foo/bar for custom post type
- Permalink for PDF of article
- Problems with rewrite rule
- Getting back a permalink from custom url
- Order custom post type posts by custom field with pretty URL
- Adding URL prefix for foreign language support
- Exclude single page from permalink rule
- help to remove last trailing slash using add_rewrite_rule
- How can I set up a secondary permalink structure?
- Rewrite rule not passing variable
- permalink and add_rewrite_rule – error 404
- How to Use metada Value in Url and is it possible? [duplicate]
- Safest way to create a custom permalink
- Rewrite Post URL so it is constructed from parent post url & child post url
- corrupted URLs – can’t leave starting page
- Create different permalinks for same post
- Multiple Taxonomy Items for Separate URLs
- Multiple URL rewrite rules and get every prams
- Using a template file for a specific custom URL
- WordPress Multisite ABSPATH and get_home_path() to check for htaccess or web.config file
- Redirect page to homepage, keeping URL
- Custom permalink question
- Added a prefix in URL permalink structure but the old structure still working!
- Permalinks Question: Adding a prefix ONLY in front of all posts with the ‘video’ post format
- Create new URL structure for custom post types
- how to have same rewrite rules for 2 different post type?
- Permalink structure /page/page/cpt-post gives 404 with pagination
- Custom Permlinks work, regular page permalinks don’t
- What permastrusture tags are generated out of the box right after creating custom post types and taxonomies?
- No Ones Been Able to Override my WordPress Rewrite Rule Issue!
- Rewrite posts url as they’re all children of a page
- Multiple Permalink Patterns for one page
- create user’s view profile link with username
- Pretty Filter URL
- WordPress Pagination Custom Rewrite Rule for Pages
- rewrites and custom links in page need help with add_rewrite_rule
- Where is wordpress redirecting wp-admin/admin/dashboard to wp-admin and how to turn it off
- Added incorrect rewrite rule now getting an error
- Why doesn’t WP update my .htaccess file?
- Pretty Permalink for Search Queries Not Working
- Permalink broken for pages after adding rewrite rule
- WordPress permalink still not working (error or not understood?)
- Only homepage working correctly, 404 error on everything else
- standard post with extra parameter brings permalink problem
- Custom rewrites for pages and categories
- WordPress custom permalinks, pages are now 404
- Add additional URL variations for a Post
- Standard Htaccess directives disappear by themselves
- make a new structure tag that does some processing