If you’re unaware, PHP 5.4 added a feature that lets you run a local development server on your machine. I found an article or two on routing local requests to WordPress.
The code works great, but I needed a little extra to get it working with the base theme I use. Roots is an amazing starter theme that bundles Bootstrap and a ton of cool features. It uses Grunt to compile LESS into minified CSS.
Roots adds some rewrites to WordPress for better looking asset URLs. Those need to be added to the router.php file. Here’s the full code:
$root = $_SERVER['DOCUMENT_ROOT']; chdir($root); $path = '/'.ltrim(parse_url($_SERVER['REQUEST_URI'])['path'],'/'); $old_path = $path; $path = preg_replace('/^\/assets\/(.*)$/', '/wp-content/themes/THEME-NAME/assets/\1', $path); $path = preg_replace('/^\/plugins\/(.*)$/', '/wp-content/plugins/\1', $path); if(file_exists($root.$path)) { if(is_dir($root.$path) && substr($path,strlen($path) - 1, 1) !== '/') { header('location: '.rtrim($path,'/').'/'); exit; } if(strpos($path,'.php') === false) { if(!strncmp($old_path, '/assets/', 8)) die(header('location: '.$path)); if(!strncmp($old_path, '/plugins/', 9)) die(header('location: '.$path)); return false; } else { chdir(dirname($root.$path)); require_once $root.$path; } }else include_once 'index.php';