wp-cli/server-command

Support custom rewrite rules

scribu opened this issue · 7 comments

The first fork of the server-command repo has popped up (yay!):

https://github.com/leoj3n/server-command/compare/roots-rewrites

It would be neat if there was a way to support custom rewrite rules in a generic way. One potential idea:

wp server --rewrites=some-file.php

The wp server command could pass the path via an environment variable to the router, which would then load it where the roots_rewrites() function is called now.

That'd work for all intents and purposes.

Haven't thought through what I'm about to say next:
Could class out the router to use traits, or to be extendable.

There isn't that much code in router.php right now to go full OOP on it. All the general-purpose utilities are already moved to router-lib.php.

Wait, if you need these rewrites for Roots to function properly, does that mean that everyone that uses Roots has to edit their .htaccess file and/or nginx configs?

only nginx, the .htaccess is handled by lib/rewrites.php

I see. But if the router loads index.php (which then loads WordPress), wouldn't it be possible to write a standard WordPress plugin that handles those rewrites?

You could check PHP_SAPI == 'cli-server' to make sure it kicks in only when wp server is used.

Sweet!