I'm trying to create a custom API endpoint in WordPress, and I need to redirect requests to a virtual page in the root of WordPress to an actual page that ships with my plug-in. So basically, all requests to the one page are actually routed to the other.
The point of this is to make the url for the API endpoint as short as possible (similar to
http://mysite.com/xmlrpc.php but to ship the actual API endpoint file with the plug-in rather than requiring the user to move files around in their installation and/or hack core.
My first stab was to add a custom rewrite rule. However, this had two problems.
- The endpoint always had a trailing slash. It became
- My rewrite rule was only ever partially applied. It wouldn't redirect to
wp-content/plugins..., it would redirect to
index.php&wp-content/plugins.... This lead to WordPress displaying either a page not found error or just defaulting to the homepage.