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 to Dynamically Change the author_base URL Slug by Language in WordPress?
- 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
- WordPress add_rewrite_rule not working with page_on_front
- Convert hex color to RGB values in PHP
- Calculate business days
- How do I make a redirect in PHP?
- How to add elements to an empty array in PHP?
- What do ++ and *+ mean?
- What’s the net::ERR_HTTP2_PROTOCOL_ERROR about?
- Undefined function mysql_connect()
- MySQL column count doesn’t match value count at row 1 [closed]
- Matching a space in regex
- Undefined function mysql_connect()
- How can I send an email using PHP?
- Fatal error: Call to undefined function mysql_connect()
- count() parameter must be an array or an object that implements countable in laravel
- Go Back to Previous Page
- How do I check if a string contains a specific word?
- How do I replace part of a string in PHP? [duplicate]
- How to declare a global variable in php?
- How to fix “Headers already sent” error in PHP
- Fatal error: Call to undefined function mysql_connect()
- How to fix ‘Notice: Undefined index:’ in PHP form action
- Loop through an array php
- Deprecated: mysql_connect()
- Where does PHP store the error log? (PHP 5, Apache, FastCGI, and cPanel)
- Chrome net::ERR_INCOMPLETE_CHUNKED_ENCODING error
- Illegal string offset Warning PHP