How to use a capture from a rewrite rule inside a php file (like single.php)?

Nicolais Tip got me on the right track; Here is the working code: // add a query_var first add_filter(“query_vars”, function($vars) { $vars[] = “myTheme_podcast_time”; return $vars; }); add_filter(“rewrite_rules_array”, function($rules) { $newRules = array(); $newRules[“(.*)/time/([\d|\:]+)s?$”] = ‘index.php?name=$matches[1]&myTheme_podcast_time=$matches[2]’; $merged = array_merge($newRules, $rules); return $merged; }); And then in single.php: $time = get_query_var(“myTheme_podcast_time”); // do stuff

Dynamic URL Rewrite rule

If you place your if/else statement within the function you call on the init hook, the redirect will only occur if your $var evaluates to false. For example function 290127_init_validate(){ if ( ! is_post_type_archive(‘book’) ) { return; } if ($var != null) { // do something } else { wp_redirect(‘new url’); } } add_action(“init”, “290127_init_validate”); … Read more

How does WordPress rewrite URLS using its PHP scripts

WordPress can make redirects internally, by wp_redirect() function. It is php code, for it to function, no redirect in Apache (httpd) or Nginx web server is needed. Also, WordPress has own rewrite API, accessible via add_rewrite_rule() and similar functions. This is also php code, which doesn’t require any support from a web server.

url restructure or rewrite having $_GET variables

From what I understand you are after pretty URLs for your form GET sending form. There are two steps involved here. First you need to prevent the default behaviour of submit form buttons: grabbing the <form> action attribute (e.g. <form action=”http://foo.com”>) and adding to it the values of the inputs as URL parameters (GET parameters). … Read more