router.php on internal server does not work correctly

0

I created a router.php file in the public root of my project, this file was made as directed in the PHP documentation for the embedded server. It works like an alteranativa to the .htaccess that is not supported by the embedded server.

<?php

if (preg_match('/\.(?:png|jpg|jpeg|gif|js|css|)$/', $_SERVER["REQUEST_URI"])) {
    return false;
} else {
    include __DIR__ . '/index.php';
}

When I use the command:

php -S 127.0.0.1:8888 public/router.php

To start my server, it does not load CSS and javascripts with the error:

  

Not Found

     

The requested resource /assets/css/bootstrap.min.css was not found on this server.

Has anyone ever had a similar situation?

I'm using php7.1 on Windows but I've already tested with version 5.6 and the same thing happens.

    
asked by anonymous 10.05.2017 / 17:11

1 answer

1

First you should run the server inside the public folder avoiding using public / router.php:

cd public
php -S 127.0.0.1:8888 router.php

Or start with an alternate document root:

php -S 127.0.0.1:8888 -t public/ public/router.php

And also, when the server starts on a different port this error can happen if the URLs present on the page are absolute and do not include the port at the address of the requested resource. For example:

http://127.0.0.1/assets/css/bootstrap.min.css

instead of:

http://127.0.0.1:8888/assets/css/bootstrap.min.css
    
10.05.2017 / 18:25