2

I developed the backend application using the WAMP stack (Windows + Apache + MySQL + PHP) and SlimPHP micro framework. It is working perfectly with WAMP but now I have to make it work in a server that is using IIS v7.5 and I'm getting an HTTP 404 error.

The frontend is an AngularJS application located in the root directory (no problem here) that uses the data obtained from the SlimPHP API located in the /api/v0 subdirectory.

Here is the structure of my web-app:

Project
|--index.html
|--styles              (directory with .css files)
|--views               (directory with .html partial views for angularJS)
|--scripts             (directory with .js angularJS scripts)
|--api
   |--composer.json
   |--vendor
      |--autoload.php
      |--slim          (directory with slim framework files)
   |--v0
      |--index.php     (SlimPHP application)
      |--.htaccess     (Apache configuration file)
      |--web.config    (ISS configuration file)
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ %{ENV:BASE}index.php [QSA,L]

RewriteCond %{HTTP:Authorization} .+
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="slim"  stopProcessing="true">
                    <match url="^api/v0/(.*)$" ignoreCase="false" />
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="api/v0/index.php/{R:0}" appendQueryString="true" />
                </rule>
            </rules>
        </rewrite>
        <httpErrors existingResponse="PassThrough" />
    </system.webServer>
</configuration>

I modified the original .htaccess proposed in SlimPHP http://www.slimframework.com/docs/start/web-servers.html but I don't know how to change the web.config.

This is my first time working with and IIS server and I had spent a lot of time researching and trying to make it work with no success.

rtribaldos
  • 1,177
  • 14
  • 28

1 Answers1

2

This configuration file web.config located in Project/api/v0/ is working for me:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="slim" 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/{R:1}" appendQueryString="true" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>
rtribaldos
  • 1,177
  • 14
  • 28