Slim Subfolder routes problem

Hello
I created a form with Slim and I have a problem when using it in subfolders.

My basePath is ‘/ app / form /’ with the following routes

//Home
$ App->get ( ‘/’, function ($ request, $ response, $ args) use ($ app) {
$Marks = new \AppController\Marks ();
Return $Marks-> all ($ this, $ response);
});

// Step 1
$ App->get ( ‘/v1/mod’, function ($ request, $ response, $ args) use ($ app) {
$results = new \AppController\Templates ();
Return $ results-> get ($ request-> getParams () [ ‘id’]);
});

The start page works correctly however when I try to access the URL ‘/v1/mod’ the page always tells me ‘404 page not found’.

With virtual servers I dont have any problem.

Thanks.

Which webserver are you using? If you look in your web server’s log file, what uri is being requested when you get the 404?

Hello tflight thanks for awnser.

My webserver is xampp and the logs says:

::1 - - [04/Dec/2016:11:36:07 -0300] “GET /app/form/public/v1/mod/ HTTP/1.1” 404 895 “-” “Mozilla/5.0 (Windows NT 10.0; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0”

Its running on localhost.

So the /public part appears to be a hint. What does your .htaccess file look like? Does public appear in your .htaccess file or vhost config? I assume app/form/public doesn’t physically exist.

Yes the public folder exists.

My tree

App/Form
|— Config/
|— Controllers/
|— Models/
|— Public/
|— Vendor/
|— .htaccess
|— Index.php

This error only appear when I access directly from tree not from virtual server.

My htaccess

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

http://localhost/app/form/ <- this not work
http://app.loc/ <-- this work correctly.

I guess I’m a little confused what you are trying to achieve for URLs and directory structure. Typically, inside your public or public_html directory is where your .htaccess and index.php files would reside. That directory is then your DocumentRoot in your vhost config.

The index.php file then acts as your “front controller” and all requests go through it. It would be accessed from http://localhost/. $app->get('/', would respond to that request. Likewise if you asked for http://localhost/v1/mod the route definition to match would be $app->get('/v1/mod',.

I think I understand what you’re trying to achieve. If you try to make the slim framework app accessible in a VirtualFolder of your domain (for example http://example.com/api/ ) then you should add/uncomment the RewriteBase / option.

Here are my config file and .htaccess

The vhost.conf apache configuration file

<VirtualHost *:80>
	Alias "/api" "/home/slava/projects/ihh-service/public"
	<Directory /home/slava/projects/ihh-service/public>
		AllowOverride All
	</Directory>

	ErrorLog ${APACHE_LOG_DIR}/angular_qt.error.log
	CustomLog ${APACHE_LOG_DIR}/angular_qt.access.log combined
</VirtualHost>

and the .htaccess inside /public folder

<IfModule mod_rewrite.c>
	RewriteEngine On
	RewriteBase /api

	RewriteCond %{REQUEST_FILENAME} !-f
	RewriteRule ^ index.php [QSA,L]
</IfModule>

I hope this post helped someone :slight_smile: