I have this code using the slim framework and php with apache2 on linux:
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
require '../../vendor/autoload.php';
$app = new \Slim\App;
#doesn't work results in URl not found in browser
$app->get('/hello','sayhi');
#works, when i just type in 'localhost/' into my webbrowser
$app->get('/',function()
{
return 'testing';
});
$app->run();
#functions
function sayhi()
{
echo 'hello world again';
}
.htaccess (same directory as my index.php file)
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
000-default.conf has the documentroot set to the directory of where my php file and .htaccess file.
When i type in 'localhost/' into my web browser the anonymous function is executed. As that's what it will do if the server recieves '/'
However when i type in 'localhost/hello' it results in URL not found, when it should execute the 'sayhi' function when the server receives this type of url.
Why is it doing this? is there something wrong in my code, as i don't understand how to go about sorting this.
I also tried setting the option to the directory of my php file
AllowOverride All
However this results in a 500 Internal error, when i have this option set. I tried following this guide: 500 internal error guide to no avail.
I have no idea how to sort this, help?
.htaccess
file? Does this file exist at all? – Nima