Url rewrite to subfolder php laravel application

Discussion in 'General troubleshooting' started by MarcHenry, May 21, 2019.

  1. Hello,

    I try to put in production my PHP application made with Laravel framework (so using a MVC model).

    My folder structure:

    / (Winhost root)
    /Application
    web.config
    /public
    index.php​

    For now I created a web.config file that I put in my website root folder (Application folder) with that code

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
       <system.webServer>
          <rewrite>
             <rules>
                <rule name="domain.com" stopProcessing="true">
                <match url=".*" />
                   <conditions>
                      <add input="{HTTP_HOST}" pattern="^(www.)?domain.com" />
                      <add input="{PATH_INFO}" pattern="^/public/" negate="true" />
                   </conditions>
                   <action type="Rewrite" url="\public\{R:0}" />
                </rule>
             </rules>
          </rewrite>
     </system.webServer>
    </configuration>
    What works
    It rewrite correctly the url that pointed to root folder (so where the logic of the application is located and sensitive folder for security) to the public folder where the index.php is located with a nice url like domain.com and not like domain.com/public/index.php

    Problem
    The url of the links are also rewritten and instead of pointing to domain.com/public/choice it point to domain.com/choice that cause 404 error.

    Thank you in advance.
     
    Last edited: May 21, 2019
  2. ComputerMan

    ComputerMan Winhost Staff

    I think you need to use the following URL Rewrite rule. You need to direct the domain name exactly where the application folder lives:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
       <system.webServer>
          <rewrite>
             <rules>
                <rule name="domain.com" stopProcessing="true">
                <match url=".*" />
                   <conditions>
                      <add input="{HTTP_HOST}" pattern="^(www.)?domain.com" />
                      <add input="{PATH_INFO}" pattern="^/public/choice/" negate="true" />
                   </conditions>
                   <action type="Rewrite" url="\public\choice\{R:0}" />
                </rule>
             </rules>
          </rewrite>
     </system.webServer>
    </configuration>
     
  3. Thank your for your answer,

    Problem is that the real start point of the application is in the public folder where is located the index.php that create dynamically pages following the url segment (here we talk about /choice).
    So /choice is not a physic folder but a named route in the logic.

    My main problem is that I don't undersant why the url of the link is rewrite like domain.com/choice that cause the 404 error instead of domain.com/public/choice
     

Share This Page