klein / klein.php

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

Can't get Klein to work #372

Closed 8lall0 closed 2 years ago

8lall0 commented 7 years ago

Hi guys, i can't get anything working. I'm using the hello world example, and that's my .htaccess in the root dir of the project.

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

It just shows a 404 when i write 'http://localhost/mywebsite/hello-world'.

Any idea?

hozzaq commented 6 years ago

i just use the one used by laravel https://pastebin.com/5UQUD4MZ

ahwelp commented 6 years ago

I allways edit the apache site conf file.

/etc/apache2/sites-avaliable/your-site.conf

<VirtualHost *:80>

DocumentRoot /var/www/html/folder/public
    <Directory /var/www>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

Enable mode rewrite a2enmod rewrite

This is my .htaccess

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.+)$ index.php?uri=$1 [QSA,L]

Restart apache

/etc/init.d/apache2 restart
peppelauro commented 6 years ago

Hi @8lall0 , you are using a subdir as your projet root so you have to do that before the request:

define('APP_PATH', '/mywebsite');

$request = \Klein\Request::createFromGlobals(); $request->server()->set('REQUEST_URI', substr($_SERVER['REQUEST_URI'], strlen(APP_PATH)));

8lall0 commented 2 years ago

Peppelauro solution worked for me.