WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I installed Monkey Man Rewrite Analyzer, i got a rule installed, it shows in the list, if i test it with monkey man it says it will fire but it doesn't in reality, whats wrong?

add_action('init', array($this, 'register_crr_jsonwebservice'), 99);

public function register_crr_jsonwebservice() {

    //Add the rewrite rule for this specific json controller
    add_rewrite_tag( '%ticket%', '([a-zA-Z0-9]+)');
    add_rewrite_rule( 'cjson/fullticket/([a-zA-Z0-9]+)/', 'index.php?p=1312&ticket=$matches[1]', 'top' );


Test this rule in MMRA:


Works fine, test it out on wordpress directly copying the same url? 404, not found... what am i doing wrong?

share|improve this question

closed as not constructive by EAMann Jan 28 '13 at 21:18

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

What's the hook? add_rewrite_tag needs to be hooked at least on init. – david.binda Jan 28 '13 at 20:00
Sorry i added it a few seconds before you posted it, it's on init – Mathieu Dumoulin Jan 28 '13 at 20:01
Closing question as per OP request. – EAMann Jan 28 '13 at 21:18

Honestly, can not debug your code, but this one works:

function register_crr_jsonwebservice( $wp_rewrite ) {            
    //Add the rewrite rule for this specific json controller
    add_rewrite_tag( '%ticket%', '([a-zA-Z0-9]+)');
    $wp_rewrite->rules = array(
        'cjson/fullticket/?([a-zA-Z0-9]{1,})/?$' => $wp_rewrite->index . "?page_id=243&ticket=".$matches[1]
    ) + $wp_rewrite->rules;

add_action( 'generate_rewrite_rules', 'register_crr_jsonwebservice' );

Do not call flush_rewrite_rules(); from this function - will lead to an error. And maybe add_rewrite_tag will have to be caled from separate function on init - have't tested that.

share|improve this answer
And what action is this bound to? If i bind this to init i don't get a parameter. – Mathieu Dumoulin Jan 28 '13 at 20:20
sorry for same mistake ;), I've edited the answer – david.binda Jan 28 '13 at 20:35
Almost works, problem is, the ticket variable doesn't seem to be set, i just get redirected to the final url for page 1312 (i changed it from your example) the variables i pass are kept but my concern now is that it actually redirects the user, that is not my intent... I just want that a certain URL maps to a specific page, is this even possible? – Mathieu Dumoulin Jan 28 '13 at 20:40
For example: /cjson/fullticket/329457289fsdfasa351/?apikey=test&secret=test should map to /json/fullticket/?apikey=test&secret=test&ticket=329457289fsdfasa351 without actually redirecting... but now it is first of all dropping the ticket variable and then it is redirecting... If i were to POST or PUT on this url, i'm not sure it would create the desired operation – Mathieu Dumoulin Jan 28 '13 at 20:42
Sorry, but I probably don't understand your question. What is your goal? You do not want to get redirected? Rewrite rule is for redirection (like .htaccess). If you want to use Ajax - read about Ajax in Plugins: codex.wordpress.org/AJAX_in_Plugins – david.binda Jan 28 '13 at 20:45

Not the answer you're looking for? Browse other questions tagged or ask your own question.