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
- Why does everybody hook add_rewrite_rule on init
- Querystring parameter getting lost in rewrite rule
- How to Rewrite WordPress URL for a Plugin
- Flush_rewrite_rules not working when settings updated
- Add rewrite endpoint to author page + pagination
- Prettified page URL w/ query var redirects to prettified page URL w/o query var
- Rewrite Rule for Custom Page with Query Vars in URL
- Redirect taxonomy to custom template to list terms in taxonomy
- How to change the matches in add_rewrite_rule
- Using add_rewrite_rule() to redirect to Front Page
- add_rewrite_rule() not working
- Determine WP_Query parameters from URL
- Can someone explain the function of the third parameter of “add_rewrite_tag”
- Can rewrites fallback if 404? Rewrite conflict issue
- Where do I USE add_rewrite_rule?
- add_rewrite_rule confusion
- add_rewrite_endpoint not working
- Create multiple rewrite endpoints for custom taxonomy archive
- Uppercase to Lowercase in URL
- How to use rewrite rule or rewrite endpoint to switch languages?
- Remove rewrite endpoint on deactivation?
- Do I need to flush rewrite rules when creating new user if using custom author rewrite rules?
- Why is add_rewrite_endpoint incompatible with /%category%/%postname%/ permalink structure?
- Changing WP_Query params with url Query Var
- Custom query var rewriting with only variable
- add_rewrite_rule redirects if value = 1
- How to add rewrite rule for external php file
- My add_rewrite_rule is returning a 404
- wordpress add_rewrite_rule not working
- force_ssl_admin() causing issues with preview links
- $wp_rewrite->rules is always NULL
- Rewrite Rules problem when rule includes homepage slug
- help with custom rewrite rules
- Order of rewrite rules when calling add_rewrite_rule
- add_rewrite_rule() not stored (I think)
- custom permalink for single post category
- WordPress add_rewrite_rule second argument not working
- flush_rewrite_rules() not working on updating Settings API
- Redirect old query string URLs to new add_rewrite_rule URL
- WordPress rewrite does not work for some reason
- Rewrite rules for short URL
- Adding a custom rewrite rule for gallery/categories page
- add_rewrite_rule issues
- Custom Endpoint For Custom Post Type from Child Theme
- add_rewrite_rule to search
- Why isn’t my rewrite rule working when there is no second parameter?
- Rewrite rules applied differently after upgrade
- How to do make mysite.com/post-name/sub-post?
- Custom rewrite rules for a page with GET variables?
- Is it possible to add a site-wide add_rewrite_rule for a multilingual site?
- How to allow WordPress to recognize a custom URL segment after a product URL and use a custom template?
- add_rewrite_rule not working for blog category page
- rewrite rule not working: redirect to php script if file exists
- Rewrite post type into a page with year filter
- How to create a custom URL to another domain in WordPress
- WordPress matching URLs with trailing tildes code correction
- Pretty links with add_rewrite_rule and add_query_var
- Flush rewrite rules when every page gives 500 error?
- Using add_rewrite_rule in conditional statement using $_SERVER
- default ‘post’ post type: not forcing url rewrite when args set
- 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?
- Social sharing conflict with Rewrite rules
- Adding custom slugs: parent-page/username/child-page/
- WordPress Custom post type single page 404 error
- How bad is flush_rules() on init hook?
- Rewrite URL to plugin file
- Rewrite for page with a possible unknown parent page
- Rewrite the WordPress URL from custom plugin
- add_rewrite_rule works only with one “directory”
- How to Rewrite WordPress URL for a Plugin
- WordPress Rewrite Rules
- How to Rewrite WordPress URL for a Plugin
- add_rewrite_rule with trailing slash redirects
- nginx + W3 Total Cache: rewrite rules issue [closed]
- add_rewrite_rule() driving me crazy, rewrite not working when analyzer says it should
- Redirect to a file in a WordPress theme directory
- What is the `rewrite_rules` option the options table in the WordPress database?
- Direct domain alias to a specific WordPress page without the page in the URL
- rewriteRules WP6
- WordPress rewrite rule – not able to access second and third parameters
- Custom URL Rewrite Rules not working
- Rewrite rule for nested URL does end in 404