I think can do:
add_action('template_redirect', 'my_func');
function my_func(){
if(is_single()){
// catch the last string
preg_match('/(.*)\/(.*?)\//', $_SERVER['REQUEST_URI'], $new_array);
$last_phrase= $new_array[2];
if(is_numeric($last_phrase)){
$id = $last_phrase;
header('location: '. get_permalink($id) , true, 301); exit;
}
}
}
Related Posts:
- Rewrite-Rules not working on a vhost, everything goes to index.php
- Custom Permalink
- corrupted URLs – can’t leave starting page
- remove SLASH on single_post but KEEP on categories and parent pages
- WordPress permalink still not working (error or not understood?)
- Need help with add_rewrite_rule
- remove “index.php” from permalinks
- How does WordPress handle permalinks?
- Rewrite Rule for Multilingual Website, Like qTranslate?
- Custom post type permalink endpoint
- Removing the redirect after changing a page’s slug
- permalink independent on the post’s name stored in the database
- Regex in add_rewrite_tag not accepting OR operators?
- How to add a custom URL placeholder to author archives?
- 301 Redirects for Changed Permalink Structure & Category Base
- URL rewrite based on a custom field value
- How can I force WordPress to redirect to canonical permalinks?
- How do I turn off 301 redirecting posts (not canonical)?
- Subdomains to pages
- Redirect old permalinks to new permalinks
- Permalink/Pagination issue: Category base name same as page name
- Passing variables through permalink structure
- + Character in permalink
- URL Rewrite + Page + Custom Post Type = Unusual Redirect
- Make post slug have priority over category slug
- How can I include a query string with get_permalink
- Permalink redirection from ‘Day and name’ to ‘Post name’
- Nicest way to 301 Redirect traffic when changing permalink settings
- Custom Rewrite with Query vars
- Using two permalinks for one post
- flexible rewrite ‘ramble’ URLs with WordPress
- Changing pemalink structure to /%post_id%/%postname%/
- add_rewrite_rule with 3 or fewer matches?
- Permalinks for WooCommerce Categories and Subcategories
- htaccess or redirect to cloak portion of a link?
- Change the custom post type permalink
- Create additional short URL with custom field and 301 redirect
- Custom rewrite rules for feeds of custom queries (query_var query strings in URL)?
- How to change URL structure for pagination pages?
- Auto 301 to full post permalink? (using /posts/%post_id%/%postname%)
- Rewrite url / permalink for default archive – yearly / monthly
- WordPress on VirtualBox – no pretty permalinks
- Rewriting permalinks with custom posts
- Rewrite rule never matching
- Stop redirecting to posts not in a category / duplicate slugs
- WordPress 3.4 Permalinks Redirection Problem
- Random Alphanumeric Key URLs
- Child pages with same slug
- Redirect old permalinks with Month and name to Post name on new site
- Permalinks, Rewrites, Get Variables, Oh My!
- Using WP rather than .htaccess to redirect pages/posts
- Date archive permalink modification
- Change permalink for a single post entry
- Does WordPress send a 301 header message when you change permalink structures?
- How to Modify Existing Rewrite Rules?
- .htaccess – Redirect duplicated post ended in ‘-number/’ to the same url without the -number/
- Top level Pages redirecting to homepage!
- 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
- WordPress redirection problem after moving to a new server?
- Specific URL Rewriting with parameters in wordpress
- How to 301 all posts
- WordPress within specific sub-directories, implicitly not root
- Page Attachment Permalink Structure based on Menu Order?
- When is it a good idea to build a permalink structure from scratch?
- 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
- Get canonical link
- Permalinks: Page Not Found
- Why is add_rewrite_endpoint incompatible with /%category%/%postname%/ permalink structure?
- Post incorrectly displaying as page
- Re-write specific custom post type category URL to go to another page
- wp_logout_url redirects to incorrect page because of pagination
- If I change permalink structures, can I use htaccess to permanantly redirect links?
- Redirect parent taxonomy to it’s child
- Need Help Correct Regular Expression Redirect Code
- How to add_rewrite_rule with two parameters to a single view page?
- Infinite redirects after changing the permalink of a page
- Rewrite Rule for default post type
- Does rename of page slugs create 301 redirects from old slug to new (same as for posts)?
- how to add rewrite rule to wordpress default post type
- RewriteRule accepts numbers but not letters in tag
- Remove custom taxonomy base from URL
- Custom query var rewriting with only variable
- Date Archives’ Permalinks under Category folder
- remove sub-category of Custom Post Type from permalink structure
- add_rewrite_rule not working for me
- Is a permastruct possible on pages?
- Using WP Rewrite, but just not “getting it”
- Changing the post date without causing 404 error
- Rewrite rule for a query string
- Change permalinks on move from one site to another
- How do I add /blog/ as a prefix to permalink structure for posts, categories & tags?
- Share same Slug for a Custom Post Type and 2 Taxonomies
- List / Get post redirects
- Redirects after permalink change