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

<system.webServer>
    <rewrite>
        <rules>
            <rule name="slim" patternSyntax="Wildcard">
                <match url="*" />
                <conditions>
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                </conditions>
                <action type="Rewrite" url="index.php" />
            </rule>
        </rules>
    </rewrite>
	
  <httpProtocol>
        <customHeaders>
            <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" />
        </customHeaders>
    </httpProtocol>
</system.webServer>
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.

$app->setBasePath(’/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...

http://www.slimframework.com/docs/v4/

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);
$app->setBasePath(’/test’);

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"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Exclude direct access to webroot/*"
                  stopProcessing="true">
                    <match url="^public/(.*)$" ignoreCase="false" />
                    <action type="None" />
                </rule>
                <rule name="Rewrite routed access to assets(img, css, files, js, favicon)"
                  stopProcessing="true">
                    <match url="^(font|img|css|files|js|favicon.ico)(.*)$" />
                    <action type="Rewrite" url="public/{R:1}{R:2}"
                      appendQueryString="false" />
                </rule>
                <rule name="Rewrite requested file/folder to index.php"
                  stopProcessing="true">
                    <match url="^(.*)$" ignoreCase="false" />
                    <action type="Rewrite" url="index.php"
                      appendQueryString="true" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

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