I think the add_rewrite_rule
is the correct route to go and I think what you have is correct also barring the Regex.
Try substituting what you have currently for this => ^my-page\/([0-9]+)\/?
.
Full code below:
function setup_filter_rewrites(){
add_rewrite_rule('^my-page\/([0-9]+)\/?', 'index.php?pagename=my-page&my_var=$matches[1]', 'top');
}
add_action( 'init', 'setup_filter_rewrites' );
Related Posts:
- Custom Endpoint Gives 404 Header
- Making extra parameters optional
- Rewrite rules and query for virtual page
- add_rewrite_rule query_var not being set
- Associate the “add_rewrite_endpoint” and “$_GET”
- Add Rewrite Endpoint to CPT Archive
- Does it still make sense using json endpoint ep_mask now that there’s the new rest api? [closed]
- add_rewrite_rule permalinks break in WordPress 4.5
- Making extra parameters optional
- Rewrite Rule for Post Meta
- WordPress add a rewrite rule to a page to accept a GET variable
- WordPress – replicate same globals, query vars and query for an alternate endpoint
- Custom Fields Query Vars and Rewrite not working
- Last query_var not working with rewritten URL
- Passing variables in the permalink structure on a custom post type
- Custom Taxonomy Endpoint Pagination using paginate_links()
- Make Two Views of Post Type Archive At Two URLs
- Custom post types and custom variables — add_rewrite_tag() question
- WordPress Custom URL Rewrites
- Does add_rewrite_rule(..) only accept “index.php” as redirect target?
- add_rewrite_rule not working for page var
- Cyrillic characters in rewrite rules cause 404 Not Found errors
- Clean URLs for custom $_GET variables
- Pagination Doesn’t Work
- why is are these rewrite_tags and rules not working?
- resolve /author/ to a page or archive (of all authors) template
- Multiple values in a rewrite rule, is it possible?
- How make a multi language routes, with rewrite rules or rewrite endpoints?
- What add_rewrite_tag()’s RegEx matches against?
- Add rewrite rule for rewrite endpoint
- add_feed and flush_rewrite_rules
- How to have multiple rewrite endpoints in the same URL?
- Change Theme from Plugin based on query_vars
- Best action to call add_rewrite_rule
- add_rewrite_endpoint() and Custom Post Type Archive
- add_rewrite_rule isnt working, not getting added to rules array, why?
- Custom Rewrite rule to match anything not already matched by WordPress
- how to add rewrite rule to wordpress default post type
- Optional all capture groups in rewrite rule
- Rewrite rule : custom post type with 2 numeric variiables
- Simple page URL rewrite with add_rewrite_rule()
- Custom rewrite_rules – only pass numbers and not alphabetic characters
- Optimal code for two add_rewrite_rule’s
- Custom URL rewrites work, but break my permalinks
- add_rewrite_rule – Additional subpages for author pages
- Rewrite custom post type URL parameters
- How do I flush rewrite rules
- Pass query vars to front page
- Custom taxonomy rewrite with query var returns %2F in URL
- rewrite url in wordpress
- A case for Hierarchical Custom Posts
- Enpoint Not Found in Rewrite Tag Permalink
- My add_rewrite_rule is returning a 404
- Rewrite rule for path of favicon.ico ( Add_rewrite_rule function possible ? )
- FLUSH_REWRITE_RULES – after or before REGISTER_POST_TYPE?
- Using get_query_var() from a plugin
- $wp_rewrite->rules is always NULL
- WordPress CPT slug and page slug conflicts
- Mod_rewritte – remove ?m=1 from url
- help with custom rewrite rules
- custom permalink for single post category
- WordPress add_rewrite_rule second argument not working
- WordPress rewrite does not work for some reason
- Rewrite rules ignored
- How to pass menu slug as a variable to wp_nav_menu?
- add_rewrite_rule issues
- Add_rewrite_rule doesn’t seem to work?
- Custom post types and custom variables — add_rewrite_tag() not working
- add_rewrite_rule to search
- Leverage WP_Rewrite to pre-validate links / detect invalid links
- Is it possible to add a site-wide add_rewrite_rule for a multilingual site?
- When request has multiple matching rewrite rules, and matched rule returns 404 – iterate to next rewrite rule
- How to allow WordPress to recognize a custom URL segment after a product URL and use a custom template?
- What’s the right way to validate JSON data coming from an AJAX POST request?
- add_rewrite_rule not working for blog category page
- Multiple URL rewrite rules and get every prams
- get_author_posts_url() doesn’t return the author URL, because of wrong author_structure
- add_rewrite_rule only works when flush first
- Homepage rewrite rule
- WordPress pass url to page template when page does not exist
- custom rewrite rules will not be added to wordpress rewrite_rules database
- rewrite rules problem with #comments-2345
- Why isn’t my rewrite rule for add_rewrite_rule not working as expected?
- A part of regular expression in add_rewrite_rule function not working
- Own query vars are not displayed
- Multiple Permalink Patterns for one page
- Complex rewrite rules with multiple variables, some the same
- how to use mutliple add_rewrite_rule?
- Pretty Filter URL
- Social sharing conflict with Rewrite rules
- Rewire Rules Front Page
- WordPress URL rewrite after changing web from Joomla
- Changing default slug of post to the post id
- How bad is flush_rules() on init hook?
- Where to hook to bypass instantiating WP_Query?
- How to Rewrite WordPress URL for a Plugin
- add_rewrite_rule with trailing slash redirects
- nginx + W3 Total Cache: rewrite rules issue [closed]
- Add additional URL variations for a Post
- Rewrite rule to index.php in theme subfolder