slimphp / Slim-Skeleton

Slim Framework 4 Skeleton Application
http://www.slimframework.com
MIT License
1.58k stars 477 forks source link

Getting 404 error for every request (IIS) #146

Closed ThisIsVegas closed 4 years ago

ThisIsVegas commented 4 years ago

This issue is similar to #131 but on IIS

My site's physical path is inetpub/www/project-name bound to port 8888. When I call an API (assuming its name is /test), calling with http://localhost:8888/public/test and http://localhost:8888/test will return 404. The route went through index.php.

I fixed it by adding a web.config file in the project root directory (not inside /public/) with these rules

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Imported Rule 1" stopProcessing="true">
                <match url="^$" ignoreCase="false" />
                <action type="Rewrite" url="public/" />
                </rule>
                <rule name="Imported Rule 2" stopProcessing="true">
                <match url="(.*)" ignoreCase="false" />
                <action type="Rewrite" url="public/index.php/{R:1}" />
                </rule>
            </rules>
            </rewrite>
    </system.webServer>
</configuration>

Now it returns the results as intended.

Referring to my comment in https://github.com/slimphp/Slim-Skeleton/issues/131#issuecomment-566887084, converting the .htaccess inside the folder /public/ is not needed and you don't need to install any packages nor set the base path with $app->setBasePath($basePath) like in Apache.

l0gicgate commented 4 years ago

This is strictly an Apache configuration issue. Not an issue with the skeleton.