External rewrite rules are awesome. They let you define rewrites that don't necessarily pass through WordPress' index.php
. This means you can map arbitrary rules to arbitrary files like:
$wp_rewrite->add_external_rule( '^somethingrandom/?$', 'wp-content/wp-uploads/hiddendirectory/somefile.php' );
Then, any request to http://site.url/somethingrandom/
will actually be served a static PHP file from a different directory. This is amazing, and it lets you do all sorts of nifty stuff.
But it only works with Apache.
The add_external_rule()
method writes its registered rules out to .htaccess
. Since Nginx doesn't use an .htaccess
file, external rules are completely ignored by that server. What I need is a server-independent way to programatically register rules like the one above. Any ideas?
.htaccess
) seems like a bad idea. So I don't thinkadd_external_rule
is really something viable to rely on, especially since it is dependent on the web server—I don't even want to think about how one would implementadd_external_rule
for IIS.