[wp-hackers] WP Rewrite

Eric Mann eric at eam.me
Sun Feb 20 04:50:14 UTC 2011


I've also asked this over on the WordPress Stack Exchange ... let's see who
answers first :-)

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.

Example:
http://mysite.com/my-api.php =>
http://mysite.com/wp-content/plugins/my-plugin/my-api.php

The point of this is to make the url for the API endpoint as short as
possible (similar tohttp://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.

   1. The endpoint always had a trailing slash. It became
   http://mysite.com/my-api.php/
   2. 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.

Ideas? Suggestions?

http://wordpress.stackexchange.com/questions/9870/how-do-you-create-a-virtual-page-in-wordpress


More information about the wp-hackers mailing list