izniburak / php-router

PHP Router, which also has rich features like Middlewares and Controllers is simple, useful and flexible router class for PHP.
https://github.com/izniburak/php-router/wiki
MIT License
238 stars 45 forks source link

404 Not Found on Built-in Web Server #35

Closed abdyek closed 4 years ago

abdyek commented 4 years ago

I started Built-in server on terminal with php -S localhost:8000 and it returned 404. I saw any error with same code on xampp server. Doesn't it support builtin web server?

izniburak commented 4 years ago

Do you have any configuration for Router instance? I've just tried on built-in server and I couldn't see any problem on the router.

abdyek commented 4 years ago

My routing is here

// index.php
require 'vendor/autoload.php';
$router = new Buki\Router();
$router->get('/api/:string', function ($val) {
    if($val=='test') {
        return 'test';
    }
});
$router->run();

.htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

https://localhost:8000/api/test url returned 404 file. But if i change 'api' keyword than it is work correctly.

izniburak commented 4 years ago

I've just tried your endpoint according to your codes, it's worked. Maybe we can debug the router on your project. Btw, which version are you using for PHP and the Router?

abdyek commented 4 years ago

We found the problem. "api" is a directory in project root file. But we don't understand why the codes isn't work correctly on built-in web server though it is work correctly on xampp. My php version is 7.4.9 I inclueded the router with composer that composer require izniburak/router Maybe the .htaccess file ignored by php for built-in.

izniburak commented 4 years ago

Of course. .htaccess file will be ignored when using built-in server. Because .htaccess file is an Apache config file. So, I think you can not access to /api/ endpoint on built-in server if you have /api/ directory in base folder.

abdyek commented 4 years ago

Thank you for the information. I will close this issue.