Remove "public" directory from Laravel 5 by IIS web.config

Asked

Viewed 756 times

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/meusite/public" this problem is fixed but, I do not have access to it in the hosting where paid...

My only solution then, is to use rules of rewrite mode directly in the file web config. The problem is that in a wide search for solutions like this on the internet, I only found rules that work when the server is apache (.htaccess) someone knows some rule to remove the public folder of an Laravel application from an IIS server?

1 answer

5


I even made a GIST to help with this https://gist.github.com/brcontainer/c2b3c75439fa3e4905e9 found it strange not to find it through the web search, but ok, I’ll bring it here.

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

However it is possible to put in everything wwwroot, including public, just create in the folder wwwroot the file web.config (out of public) and place 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>

This is assuming you have already set up PHP, such as Fastcgi or CGI

  • worked, gave an error at first but it was missing permission in the folder inside the server, thank you very much

Browser other questions tagged

You are not signed in. Login or sign up in order to post.