Search code examples
phpiis-8fat-free-framework

File or folder exist, but throws 404 in IIS web server


I built a web application with F3 framework. On my local (XAMPP), everything went well. But, after I uploaded it to the server (IIS Web Server), the message 404 - "file or folder doen't exist" appeared. I am confused, what causes this problem can occur.

Note :

  • I create new site in IIS with the root folder pointing to "D:/www/my-project".
  • Default root folder is "C:/inetpub/wwwroot".
  • There are a domain that points to the ip server.
  • When I access the domain, the first page appears. But after switching page / route, the next page throws 404.

Solution

  • Create web.config file at the root and put the code as below (this config might differ based on your app structure)

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
      <system.webServer>
        <rewrite>
          <rules>
            <rule name="Application" stopProcessing="true">
              <match url=".*" ignoreCase="false" />
              <conditions logicalGrouping="MatchAll">
                <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
              </conditions>
              <action type="Rewrite" url="index.php" appendQueryString="true" />
            </rule>
          </rules>
        </rewrite>
      </system.webServer>
    </configuration>