wp-cli / server-command

Launches PHP's built-in web server for a specific WordPress installation.
MIT License
67 stars 19 forks source link

Support custom rewrite rules #2

Closed scribu closed 11 years ago

scribu commented 11 years ago

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.

leoj3n commented 11 years ago

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.

scribu commented 11 years ago

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.

scribu commented 11 years ago

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?

leoj3n commented 11 years ago

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

scribu commented 11 years ago

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.

leoj3n commented 11 years ago

Good ideas; seems to work: https://github.com/leoj3n/wp-server-roots-rewrites

scribu commented 11 years ago

Sweet!