Ok, resolved it in 404.php
<?php
$klo_link = $_SERVER['REQUEST_URI'];
if (preg_match("/^\/[a-zA-Z0-9\-\_]+\/$/", $klo_link)) {
//echo "A match was found. \n";
//echo $klo_link;
header("HTTP/1.1 301 Moved Permanently");
header("Location: ".get_bloginfo('url')."/a".$klo_link);
exit();
}else {
get_header();
}
Put that at the beginning of the 404.ph
Related Posts:
- Redirect old permalinks with Month and name to Post name on new site
- Custom Permalink
- Changing the post date without causing 404 error
- Extending page urls without getting a 404
- After server migration only the homepage works
- Changing permalinks gives me 404 errors on nginx
- How does WordPress handle permalinks?
- Removing the redirect after changing a page’s slug
- Setting 404 page in Nginx
- Including category-base in a post permalink results in 404
- WordPress thinks my custom route is a 404
- 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
- Passing variables through permalink structure
- + Character in permalink
- How can I include a query string with get_permalink
- Permalink redirection from ‘Day and name’ to ‘Post name’
- Homepage loads but all permalinks are 404 when using nginx & PHP-FPM
- Nicest way to 301 Redirect traffic when changing permalink settings
- 404 on category.php pagination
- Changing pemalink structure to /%post_id%/%postname%/
- htaccess or redirect to cloak portion of a link?
- Redirect short-form URL to long-form URL (post_id to post_id + post_name)
- Auto 301 to full post permalink? (using /posts/%post_id%/%postname%)
- Posts not working on windows after changing permalinks
- removed index.php now all pages 404
- WordPress on VirtualBox – no pretty permalinks
- Stop redirecting to posts not in a category / duplicate slugs
- WordPress 3.4 Permalinks Redirection Problem
- Random Alphanumeric Key URLs
- Rewrite-Rules not working on a vhost, everything goes to index.php
- Using WP rather than .htaccess to redirect pages/posts
- Does WordPress send a 301 header message when you change permalink structures?
- Permalinks Structure and 404 Question
- .htaccess – Redirect duplicated post ended in ‘-number/’ to the same url without the -number/
- Top level Pages redirecting to homepage!
- Attachment page 404 not found when image is attached to post
- WordPress redirection problem after moving to a new server?
- After moving from subdirectory to home, home page does not display
- Specific URL Rewriting with parameters in wordpress
- Changes to permalink structure results in 404 error for all pages other than home
- permalink changed, now getting 404 for every pages
- Permalinks broken regularly
- 404 Page Not Found for Only One Post
- How to 301 all posts
- Permalink /%category%/%postname%/ returns 404 on OSX
- WordPress within specific sub-directories, implicitly not root
- Permalinks keep reverting to 404 unless I re-save them
- Get canonical link
- Clean install – Changing permalinks in twentyeleven give 404
- Problems redirecting to “pretty” permalinks (wordpress in Subdirectory)
- Permalink change made author archive vanished
- Post incorrectly displaying as page
- Permalinks okay some pages but 404 error on others
- 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
- AWS WordPress Install – pages/posts 404 on restart until updating permalinks
- WordPress 404 in development area
- Need Help Correct Regular Expression Redirect Code
- Permalinks by page/post name returning 404
- Infinite redirects after changing the permalink of a page
- Does rename of page slugs create 301 redirects from old slug to new (same as for posts)?
- Editing Pages Give 404 Error After WordPress Upgrade in Admin Panel
- page nested 3 levels deep shows 404
- Nginx Rewrite Rule:: index.html added to every permalink
- Moving local wordpress page to a real server subdomain broke my permalinks?
- Change permalinks on move from one site to another
- How to make /search/ without parameters not return a 404?
- 404 Error Problems with sCategory Permalink plugin
- Why does the ‘Month and Name’ Permalink Format not Work on my new WordPress Site (running on IIS7)?
- List / Get post redirects
- WordPress post-name permalink redirects to site.com
- Redirects after permalink change
- Redirect /%year%/%monthnum%/%day%/%postname% [closed]
- Page preview is shown, updating page gives 404 error
- How to 301 redirect from one url to another properly
- Redirect a Blogger Page URL to wordpress
- Redirecting all posts after changing URL structure with htaccess
- Redirect all posts permalinks from “.html” to “/”
- Edit page slug after save, cause 404 by linked pages
- Unable to get /%postname%/ permalinks working, 404 on all links
- Correct permalinks and 404-error
- What would cause a theme to add extra characters to blog post links?
- Permalink Doesnt Work – URL Not Found
- Getting 404 when Access post which name start with Digit
- WordPress 4.4 old permalink redirect
- 404 when going to /blog
- Permalinks 404 error with HTTPS host
- Permalinks stopped working – NO update, mod_rewrite enabled, .htaccess not touched
- how to redirect old blog post urls when permalinks are changed
- WordPress can generate numeric permalinks, which then 404
- Htaccess https 301 problem
- 301 Redirect for Non-Date Based URL’s
- Custom permalink structure gives 404
- Accessing Subdirectories in WordPress Install