Remove "public" directory from laravel 5 through IIS web.config

4

I have an IIS server where a site built in Laravel 5.3 will be hosted and I need to remove the public folder from the url.

NOTE: I am aware that if I enter the IIS manager and change the destination folder of the site to "wwwroot / mysite / public" this problem is solved but I do not have access to that in hosting in which I pay ...

My only solution then is to use rewrite mode rules directly in the web.config file of the laravel root folder. The problem is that in a broad search for solutions like this on the internet, I only found rules that work when the server is apache (.htaccess) does anyone know of any rules for removing the public folder from a Laravel application from a server in IIS?

    
asked by anonymous 18.11.2016 / 18:12

1 answer

5

I even made a GIST to help with this link I found it strange not to find it through web finders, but Okay, I'll bring it here.

You can put all content out of the %SYSTEMROOT%\inetpub\wwwroot folder, and within wwwroot put the contents of ./public .

However, it is possible to put everything inside of wwwroot , including public , just create in the wwwroot folder the web.config file (out of public ) and put the following content:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <defaultDocument>
            <files>
                <clear />
                <add value="index.php" />
            </files>
        </defaultDocument>
        <rewrite>
            <rules>
                <rule name="Laravel Force public">
                    <match url="(.*)" ignoreCase="false" />
                    <action type="Rewrite" url="public/{R:1}" />
                </rule>
                <rule name="Laravel Routes" stopProcessing="true">
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <match url="^" ignoreCase="false" />
                    <action type="Rewrite" url="public/index.php" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

Assuming you have already set up PHP, such as FastCGI or CGI

    
18.11.2016 / 18:32