How to Rewrite WordPress URL for a Plugin

Create an endpoint. In the callback function for the endpoint call your plugin functions internally, so the whole WordPress environment is available and you are still on the same domain, no matter where the plugin URL is.

Plus, make sure not to flush the rewrite rules on every page load, use the (de)activation hook for that.