[wp-hackers] Wp rewrite rule binding to admin-ajax.php

Lox lox.dev at knc.nc
Thu Mar 10 21:47:26 UTC 2011

2011/3/11 Eric Mann <eric at eam.me>

> You probably could ... I've managed to do something similar in the past.
>  But what exactly are you trying to accomplish?  The rewrite engine is
> meant
> to manage pretty permalinks and route them through WordPress to process a
> query.  Anything accessing admin-ajax.php (according your message subject)
> would be behind the scenes and wouldn't need human-readable pretty
> permalinks.
> Give us some examples of what you're trying to do ...

Here is the code snippet:

function create_rewrite_rules($rules) {

global $wp_rewrite;

$new_rules = array( '^plugin-api/(.*?)/(.*?)/?$' => 'index.php' .
'wp-admin/admin-ajax.php?action=test&do=' . $wp_rewrite->preg_index(1) .

 '&command=' . $wp_rewrite->preg_index(2) );

$rules = $new_rules + $rules;

return $rules;

add_filter('rewrite_rules_array',  'create_rewrite_rules' );

So going to http://mywebsite.com/plugin_api/do/something should be rewrote

lox.dev at knc.nc

More information about the wp-hackers mailing list