klein/klein.php

Can't get Klein to work

8lall0 opened this issue · 4 comments

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?

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

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

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)));

Peppelauro solution worked for me.