klein / klein.php

A fast & flexible router
MIT License
2.66k stars 290 forks source link

Routing doesn't work #348

Open Irikos opened 7 years ago

Irikos commented 7 years ago

Hello,

I can't seem to make routing work. Here's the htaccess file, which does redirect every request to index.php. However, in index.php, it doesn't respond to GET request.

.htaccess:

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

index.php:

<?php
require_once __DIR__ . '/vendor/autoload.php';

$klein = new \Klein\Klein();

$klein->respond('GET', '/hello-world', function () {
    return 'Hello World!';
});

$klein->dispatch();

If I change it to

$klein->respond(function () {
    return 'Hello World!';
});

It will work, and show this on every link (that doesn't already exist).

I also found this link on stackoverflow with the same problem (from a few years ago), but with no solution specified: http://stackoverflow.com/questions/20269954/klein-routes-dont-return-anything

Any ideas?

leosilvano commented 7 years ago

is the index file in in the root of the project?

Irikos commented 7 years ago

yes

leosilvano commented 7 years ago

I was having the same issue but it was because i was testing it in on a subfolder called api, so for every url string i just added /api on the start it worked like a charm.

maybe its your .htaccess config?

this is my .htaccess file:

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(.*)$ index.php [NC,L]