Page not found problem with iis

I’m uploading slim framework project to iis server to be the backend of my angular project but when I enter to the website it produces page not found error in HTML format

my web config is like this

            <rule name="slim" patternSyntax="Wildcard">
                <match url="*" />
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                <action type="Rewrite" url="index.php" />
            <add name="Access-Control-Allow-Origin" value="*" />
            <add name="Access-Control-Allow-Methods" value="*" />
            <add name="Access-Control-Allow-Headers" value="Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, role, Access-Control-Request-Method, Access-Control-Request-Headers" />
please could any one help me with this?

Running a Slim 4 app in a sub-directory requires a base path. In your case it’s /test.


Thank you for your response.
where I should put this instruction ? in the public/index.php file or where?

Directly after creating the $app instance.

$app = AppFactory::create();

// here...

I’m using version 3 from slim framework
I tried to put this line of code after the creation of the app like this

$app = new \Slim\App($settings);

but it can not find the index file anymore and gives me this page

The setBasePath method exists only since Slim 4.

So there is not any solution for my problem here ?

There is a solution, but I have not tested it with Slim 3. You can try this anyway:

IIS does not natively support .htaccess files. While there are add-ons that can add this support, you can also import htaccess rules into IIS to use the native rewrites. To do this, follow these steps:

  1. Use Microsoft’s Web Platform Installer to install the URL Rewrite Module 2.0 or download it directly (32-bit / 64-bit).
  2. Create a new file called web.config in your Slim root folder.
  3. Using Notepad++ or any XML-safe editor, copy the following code into your new web.config file:
<?xml version="1.0" encoding="UTF-8"?>
                <rule name="Exclude direct access to webroot/*"
                    <match url="^public/(.*)$" ignoreCase="false" />
                    <action type="None" />
                <rule name="Rewrite routed access to assets(img, css, files, js, favicon)"
                    <match url="^(font|img|css|files|js|favicon.ico)(.*)$" />
                    <action type="Rewrite" url="public/{R:1}{R:2}"
                      appendQueryString="false" />
                <rule name="Rewrite requested file/folder to index.php"
                    <match url="^(.*)$" ignoreCase="false" />
                    <action type="Rewrite" url="index.php"
                      appendQueryString="true" />

Once the web.config file is created with the correct IIS-friendly rewrite rules, Slim’s links, CSS, JavaScript, and rerouting should work correctly.

If you run Slim 3 is a sub-directory you may also have to fix the basePath:

$container['environment'] = function () {
    $scriptName = $_SERVER['SCRIPT_NAME'];
    $_SERVER['SCRIPT_NAME'] = dirname(dirname($scriptName)) . '/' . basename($scriptName);

    return new \Slim\Http\Environment($_SERVER);

This setup assumes that you store your front-controller file (index.php) under: {project-root}/public/index.php