Hello everyone, i try to explain my problem.
I’m new with slim and i started to follow the tutorial , but it doesn’t work.
Oh better it’s work if i don’t use the request e response.
I started with the code of tutorial and that doesn’t work i have that result
at this url : mylocalhost/hello/someone Not Found The requested URL /mylocalhost/hello/someone was not found on this server. Apache/2.4.18 (Ubuntu) Server at mylocalhost Port 80
i tested my virtual host and it work, infact with this code it’s work:
require ‘vendor/autoload.php’;
$app = new \Slim\App; $app->get(’/’, function () {
echo “Hello”;
});
$app->run();
at url
mylocalhost/ it’s work i can see hello in my screen!
but if i try to put a root like:
$app->get(’/hello’, function () {
and i put this url on browser o try with postman mylocalhost/hello it’s dosn’t work and i have Not Found The requested URL /mylocalhost/hello/someone was not found on this server. Apache/2.4.18 (Ubuntu) Server at mylocalhost Port 80
if i try mylocalhost/ i have Page Not Found The page you are looking for could not be found. Check the address bar to ensure your URL is spelled correctly. If all else fails, you can visit our home page at the link below. Visit the Home Page
i had .htacces like this
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
What does your directory structure look like? Is your front controller (index.php) running inside a mylocalhost folder within your public or public_html folder? It looks like you might be trying to run Slim from within a subdirectory of your document root.
Okay. I’m not sure why you are trying to access mylocalhost/hello when the route is '/hello' instead of the URL /hello. Since you haven’t defined a route that begins with /mylocalhost, any URLs that try to go there will not be found.
i no undestund sorry
if i put in route
$app->get(’/’, function () {
the string “/” is mylocalhost isent’t it?
and if i write
$app->get(’/hello’, function () {
the string "/hello
is for all route “mylocalhot/hello” isnt’it?
i have to create the subdirectory /hello into my project?
sorry but i realy not undestund
thank for your interesting
No, you should not create a subdirectory in your project.
$app->get('/', function () {
// would respond to something like http://example.com/
}
$app->get('/home', function () {
// would respond to something like http://example.com/home
}
$app->get('/home/{name}', function () {
// would respond to something like http://example.com/home/mangel
// or would also respond to http://example.com/home/tflight
}
Or if using something like MAMP
$app->get('/', function () {
// would respond to something like http://localhost:8080/
}
$app->get('/home', function () {
// would respond to something like http://localhost:8080/home
}
$app->get('/home/{name}', function () {
// would respond to something like http://localhost:8080/home/mangel
// or would also respond to http://localhost:8080/home/tflight
}
that is that i do… but dosn’t work i no undestund why… o better
$app->get(’/’, function () {
// would respond to something like http://example.com/
that-s work
but
$app->get(’/home’, function () {
// would respond to something like http://example.com/home
}
dosent’t work…
i try to explain better
DocumentRoot /var/www/html/htdocs/myprogect
into /var/www/html/htdocs/myprogect i have index.php
ServerName matteo.local
now if i write in code
$app->get(’/’, function () {…
and i do matteo.local
it’s work
but if i write in code
$app->get(’/hello’, function () {
and i try
matteo.local/hello
it-s dosn’t work
Have you turned on AllowOverride All in Apache? Can you be certain your .htaccess file is being loaded?
One way to check quickly would be to change your .htaccess file to say anything invalid. For example just put the word hello in and save. If you load http://matteo.local and it doesn’t fail, then your .htaccess file is not being properly loaded.
If you intentionally broke your .htaccess like I suggested and you still get the same result (working for the / route but not for /hello) then that leads me to believe your .htaccess file is not being loaded. How did you install Apache?
i don’t remember, but probably i installed LAMP, but i had resolve in part…
I looked the file apache2.conf and i change AllowOverride All , sorry
i before had change only in file. conf for virtualHost and i forgot apache2.conf,
I had change now and i set again my .htaccess and now work! but work only if i put index.php in url
mylocalhost/hello/matteo dasent work
mylocalhost/index.php/hello/matteo work
Something isn’t correct with your Apache setup. I noticed the config you put in your .htaccess is different from what is recommended. Try this, exactly.
I do it and dosn’t work, i try again to modyfy .htaccess and write “hello” and anything cange,
my apache dosn’t load .htaccess
now it work with MyLocalHost/index.php/hello/matteo
probably because i change in apache2.conf
AllowOverride All
but .htaccess dosn’t load
but
MyLocalHost/hello/matteo dosn’t work