Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kreierson's avatar

Laravel on IIS

Ok so I have been trying to get this to work for days so I have finally decided to ask.

I need to get Laravel to work with IIS. My company uses windows authentication and we are building a helpdesk system. They would like it to automatically authenticate the user based on the user logged into the computer. I have everything working just fine until I try to set up a route. So if I go to http://localhost I can get there just fine. But if I set up this route

Route::post('login', 'PagesControllter@postLogin');

Then try to submit to that route I always get a 404 error back. Below is my web.config file.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.webServer>
        <handlers>
         
        </handlers>
        <rewrite>
            <rules>
                <rule name="Imported Rule 1" stopProcessing="true">
                    <match url="^(.*)/$" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
                    </conditions>
                    <action type="Redirect" url="/{R:1}" redirectType="Permanent" />
                </rule>
                <rule name="Imported Rule 2" stopProcessing="true">
                    <match url="^" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

I am pointing my web application in IIS to the public directory in Laravel. Any help would be greatly appreciated.

Kyle

0 likes
6 replies
Snapey's avatar

Did you read all the comments on this thread (not just the answer marked as correct) https://laracasts.com/discuss/channels/general-discussion/iis7-laravel-5

This rewrite rule looks better that the one you posted https://gist.github.com/jatubio/80dfc57fc18546706ec0 since the requested page is being passed through to index.php

I looked at a few other different setups, some on Azure that seem to use the same rewrite rules. This one, and others https://gist.github.com/bobsta63/7d5d4af32491c11dafc4 have appendQueryString="true" after the rewrite to index.php

spekkionu's avatar

I seem to remember that there are some cgi settings in the php.ini that need to be changed for IIS.

Without them some of the path parameters on the request don't get populated correctly which many mvc frameworks use to parse the url to do their routing.

This was at least true a number of years ago and I'm not sure if things have changed. I haven't worked with IIS in a while. The IIS url rewriting was still in beta the last time I used it.

kreierson's avatar

WOW....Thank you guys for your time and input. After spending an entire day on this I got pissed and uninstalled URL Rewrite and then reinstalled. Now it works perfect. You have to love IIS. Thanks again for your help.

manchote's avatar

@kreierson , I've the same problem that you, after check :

  • good extensions
  • good PHP version
  • I put url root IIS on public folder through Right clic on website you want install laravel on IIS interface and "Manage WebSite" > "Advanced Settings" and change the directory for public like root website
  • Give the rights to write for 2 users : Users ou IIS_IUSRS for 3 directories :
  • /vendor
  • /storage
  • /bootstrat/cache

After that i can see the laravel page and i am happy :)

Please or to participate in this conversation.