As the question was modified, I modify my answer. This task is relatively easy, doable just with a single rewrite rule, which converts everything after /mypage/ string into a variable – I call it var. As this is added to query_vars via hook, is reachable via global $wp_query; echo $wp_query->var;.
add_filter( 'query_vars', 'binda_query_vars' );
function binda_query_vars( $vars ) {
$vars[] = 'var';
return $vars;
}
add_action( 'generate_rewrite_rules', 'binda_rewrite_rules' );
function binda_rewrite_rules( $wp_rewrite ) {
$mypage_id = 4; //setup your 'mypage' ID
$wp_rewrite->rules = array(
'mypage/(.+?)/?$' => $wp_rewrite->index . '?page_id='.$mypage_id.'&var=" . $wp_rewrite->preg_index( 1 ),
) + $wp_rewrite->rules;
}
Related Posts:
- Newbie question: no index.php? in my plain wordpress permalink
- Static variable and add_rewrite_rule?
- Performance impact of rewriting WordPress URLs
- Changes in permalink structure in WordPress and how to apply to in-site links
- WordPress Persistent connection rule does not work for “posts”
- Append query string to all URL’s
- custom rewrite rule help! Custom rewrite rules not applying to custom post type
- Create custom permalinks to show Custom Post Type’s relationship?
- Rewrite with pagination /foo/page/2/ to posts of a given category, page 2
- WordPress add parameters with friendly url structure
- How can I modify the permalink via a filter?
- Can I write ‘RewriteCond’ using ‘functions.php’?
- add_rewrite_rule with bottom priority doesn’t handle the WordPress pages
- WordPress Rewrite API calls not creating new rules
- Change links automatically to affiliate links
- Rewrite sub folder dynamically with country code in WordPress using PHP
- Use WordPress’ URL rewrite engine
- Rename “Portfolio” slug?
- How to rewrite URL with PHP variables with htaccess to a normal looking URL?
- Nesting if statements to echo only one string based on what tag was filtered?
- How to change home or site url using action hooks or filter?
- Apache Fallback instead of add_rewrite_rule
- Why do WordPress rewriites seem to work differently for posts vs pages?
- Is sanitize_title_with_dashes formatting function too liberal (in terms of accepted characters)?
- subdirectory index.php is not working
- custom url rewrite for wordpress
- Use URL Rewrite as well as $_GET parameters in URL?
- How to modify URL (add GET values) after front end form submission?
- parts of url disappear when using # inside href=”” [closed]
- Add .htm extention to a custom taxonomy
- Help with .htaccess and Login with Subfolders
- WordPress add_rewrite_rules for custom URLs ending in .html
- Divi change project category slug
- How to override url params with rewrite rules vars?
- How to add a rewrite endpoint to unattached media?
- Using rules in Posts
- How do i add slugs to a URL, but still redirecting to the same page
- Nginx WordPress and another Web app URL structure
- Custom post type url Rewrite (conflicting with page url)
- Why is home page content not displaying with this rewrite rule?
- Modifying WP URL handing code?
- How to deal with a GET variable of ‘name’?
- Prevent Buddypress Rewrite Rules on Non-Buddypress pages/posts
- How to define a rule in functions.php that ONLY disables the default wp functionality that undesirably changes ‘&’ to ‘#038;’?
- Change permalink structure specific category
- How to pass username in affiliate link in wordpress website
- add_rewrite_rule to load different page, without changing URL in browser
- Test the existence of a page/article by its URL, taking in consideration the URL rewriting by filters
- url not using query string no longer working
- WordPress rewrite rule depend on meta values not ids
- Current WordPress Page Title as Search Parameter into A Tag
- Rewrite rule for wp
- How does one make a URL return dynamic JSON with custom Content Type?
- Change custom rewrite rule when permalink is updated/changed
- URL rewrite rule
- Rewrite URL of Specific Post of Custom Type
- How does WordPress rewrite URLS using its PHP scripts
- Rewrite /keyword1+keyword2.html to search page | .htaccess
- How can I turn a url with get method as a clean url with segment as the get method?
- add_rewrite_rule questions
- rewrite_rule – working fine but broken for pagination
- WordPress Rewrite Issue
- How to print redirected query string variables to the page?
- Multiple URL from Custom post name
- Why isn’t my custom function kicking in from my functions.php file?
- how to exclude admin page from add_rewrite_rule in wordpress
- Difference in Get Variable Location
- WordPress adding in site URL to header links
- Dynamically append custom post type to end of url
- Custom taxonomy with page post type – WordPress
- add_rewrite_rule image from /images/site2/favicon.ico to /favico.ico
- Same Custom Post Type Slug and Custom Taxonomy Slug, with hierarchial unique permalink structure
- Remove slug of multiple custom post types with and without hierarchical
- How to call a PHP function from Javascript in WordPress
- is there a simple way to list every templates / php files used to generate a specific page?
- Correct way to make static pages editable in wordpress
- Class ‘WP_Widget’ not found
- Listing and displaying WooCommerce Shipping Zones in the frontend? [closed]
- how to trace notice warning on core function is_page() & is_singular in class-wp-query.php
- A function that returns true when the Author is a certain role is_author(admin)?
- Add a class to the anchor tag on HTML5 gallery
- Display a specific category of products in shop page and disable code for specific actions
- Hide HTML element (by class or ID) with PHP
- wp_force_remove_style’ not found
- Pagination on Custom Post
- jQuery accordion menu
- Restrict characters in comment section
- Adding custom url to readmore link using get_permalink()
- Remove submenu item from list
- Is there way to toggle the publish date display?
- How to use wp_ajax_set_post_thumbnail?
- Get product price in a different currency using WooCommerce Currency Switcher
- Cannot fetch posts with certain ‘product_cat’. WP_Query is empty
- Change CPT permalink to use the category
- Create a hierarchical loop at predefined markup requirements
- Setting ‘post_format’
- nested divs, classes for a grid in loop [duplicate]
- Why can’t I include echo inside a variable? [closed]
- WP_Query not returning results
- How do I link the side images?