Slim Framework index.php in public folder .htaccess

3.4k Views Asked by At

I'm using Slim Framework v3, in particular I'm using this project: https://github.com/slimphp/Slim-Skeleton

My problem is to run my project on an apache server, if I try to reach with this url http://localhost/slim-app/some_route I receive this error:

error1

But if I try to navigate to http://localhost/slim-app/public/some_route it works.

My folder structure looks like this:

/slim-app
 .htaccess
 /logs
 /public
  /css
  /js
  index.php
  .htaccess
 /src
  /helpers
  routes.php
  settings.php
 /templates
  file.twig
 /vendor

This is the .htaccess file in the root project folder "slim-app":

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /slim-app/

    RewriteCond %{THE_REQUEST} /public/([^\s?]*) [NC]
    RewriteRule ^ %1 [L,NE,R=302]

    RewriteRule ^((?!public/).*)$ public/$1 [L,NC]
</IfModule>

This is the .htaccess file in the public directory:

<IfModule mod_rewrite.c>
  RewriteEngine On

  # Some hosts may require you to use the `RewriteBase` directive.
  # Determine the RewriteBase automatically and set it as environment variable.
  # If you are using Apache aliases to do mass virtual hosting or installed the
  # project in a subdirectory, the base path will be prepended to allow proper
  # resolution of the index.php file and to redirect to the correct URI. It will
  # work in environments without path prefix as well, providing a safe, one-size
  # fits all solution. But as you do not need it in this case, you can comment
  # the following 2 lines to eliminate the overhead.
  RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
  RewriteRule ^(.*) - [E=BASE:%1]

  # If the above doesn't work you might need to set the `RewriteBase` directive manually, it should be the
  # absolute physical path to the directory that contains this htaccess file.
  # RewriteBase /

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

There are 0 best solutions below