You could force the redirect this way by checking for the get_var query value:
add_action('init','my_redirect_check');
function my_redirect_check() {
if (isset($_GET['my_var'])) {
if ($_GET['my_var'] != '') {
if ($_SERVER["HTTPS"]) {$location = 'https://';}
else {$location = 'http://';}
$location .= $_SERVER['SERVER_NAME'];
$location .= strtok($_SERVER['REQUEST_URI'],'?');
$location = trailingslashit($location);
$location .= $_GET['my_var'];
$location = trailingslashit($location);
wp_redirect($location); exit;
}
}
}
Note: you will lose any other querystring values this way, but you could always rebuild and append those also if needed.
Related Posts:
- How to Modify Existing Rewrite Rules?
- Creating an alternate path for a page
- WordPress keeps removing query var from the URL
- Pretty Filter URL
- Add additional URL variations for a Post
- remove “index.php” from permalinks
- Passing and retrieving query vars in wordpress
- How does WordPress handle permalinks?
- Creating custom permalink structure for languages
- How to remove dates from existing permalinks?
- Getting the Site URL Including the Front Base
- Date based URLs for custom posts and pagination
- How to custom change author base without $this->front?
- How to prevent the default home rewrite to a static page
- URL Rewrite + Page + Custom Post Type = Unusual Redirect
- Make post slug have priority over category slug
- How to remove the index.php in the url?
- Remove subfolders from URL
- Remove parent slug for child pages
- flexible rewrite ‘ramble’ URLs with WordPress
- Rewrite user profile URL to be human friendly
- Image Attachment Url Rewrite
- Rewrite Page with a slug before page name
- Can’t get rewrite rules working
- Incorrect 404 for pages when using permalink, a static front page, and posts page
- When is it a good idea to build a permalink structure from scratch?
- How to improve WordPress security by hiding non public facing files?
- If the only permalink setting is %postname% what happens in the case of old duplicates?
- Change author slug and functionality
- Use Regular Expression to get tag from permalink url during wp_rewrite in generate_rewrite_rules
- Is it possible to keep all special letters for foreign languages in slug as in title?
- remove sub-category of Custom Post Type from permalink structure
- WordPress Permalinks & Nginx Rewrite Rule Not Working
- How to redirect to correct pages after permalink structure change
- Rewrite rule for a query string
- Add prefix to page URL based on the page template
- How to remove specific category from URL in WordPress
- Need to add trailing slash to all internal links relative and absolute
- Redirect Uploads Folder to Query Vars in WordPress
- Custom permalink leads to index page
- Permalinks 404 error with HTTPS host
- Mirror content based on URL slug
- How to change hierarchical page permalinks to be flat
- How to rewrite a URL to another rewritten URL without changing the address?
- How can I emulate permalink behaviour on static pages
- Format HTTP links
- wordpress how to replace url /bar with foo/bar for custom post type
- Change directory url to be same as page permalink?
- How Do I get the author’s page id?
- Getting back a permalink from custom url
- Permalinks on Windows IIS not working and web.config breaks site – does wordpress not support windows server now, if so how?
- Order custom post type posts by custom field with pretty URL
- Show category name in the post URL only for specific categories
- Adding URL prefix for foreign language support
- 404 permalink errors on Pages only
- Exclude single page from permalink rule
- Bulk append URL (add word to slug)
- help to remove last trailing slash using add_rewrite_rule
- How are WordPress Page URLs affected by permalink settings?
- WordPress pages and posts are redirecting to server IP address instead of domain URL [closed]
- Change permalink to attachment
- Access posts while mod_rewrite is broken
- “set_front” => false on custom post type breaks wp_list_categories links [closed]
- Problems with permalinks (.htaccess not working)
- Subdomains pointing to a permalink URL
- Can I change the URL structure for a CPT only?
- How to set add_query_arg properly for home page?
- corrupted URLs – can’t leave starting page
- Make the blog page a child of another page and rewrite the blog url
- Multiple Taxonomy Items for Separate URLs
- MySQL-inserted custom taxonomy term lead to 404, flush rewrites doesn’t help
- How to construct a dynamic rewrite rule for child pages that passes more than one query var
- Multiple URL rewrite rules and get every prams
- Permalink not changing according to post type
- Website URL Permalinks
- Passing parameter through permalink structure
- Add word to permalinks does not transform the urls
- Custom permalink question
- append current user-id to all internal permalinks
- rebuilding/ rewriting a url to make it SEO friendly
- No Ones Been Able to Override my WordPress Rewrite Rule Issue!
- Pagination links for taxonomy archive page 404 error on every page except first
- Change all pages permalinks instead of hierarchical to have id of the page
- How to rewrite a folder in WordPress?
- Rewrite single template permalink?
- rewrites and custom links in page need help with add_rewrite_rule
- Category-dependent custom permalink
- How to create an IIS7 re-write rule for a single category
- Folder Name and Category Name WordPress
- Although rewrite engine is on, I get 404 not found on every page
- Customized author slugs not working with get_author_posts_url method
- Editing the variables in a custom URL
- ?posts_type=xxx not rewritten
- Custom permalink variable on single post
- How to change pagination base from slash to query form?
- region selection
- WordPress custom permalinks, pages are now 404
- Include language variable in url
- Creating complex URLs with WordPress permalink structure
- How to make my custom permalink pull up the correct post