Setting method for entry files such as thinkphp in the public directory.

Published: 2018-10-24

Our company's virtual hosting sites all use the default wwwroot directory and do not support custom modifications, but now more and more ThinkPHP application frameworks place the application entry in the public directory, causing them to fail to run properly. In response to this situation, our company has proactively adjusted to support switching the directory to the public directory. Currently, Linux supports modification, while Windows systems do not yet support it.

Linux system hosts can click [Switch Main Site Directory] in the hosting control panel to perform the operation, as shown below:

image.png

image.png


Windows systems can use the following method:

In the hosting control panel, click [Set Homepage], set the homepage to public/index.php, and place it in the first position.

image.png

Since pseudo-static issues are also involved, some application configurations may not be applicable, and the corresponding pseudo-static rules need to be added.

Pseudo-static rules under IIS7:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
      <rewrite>
        <rules>
          <rule name="public" stopProcessing="true">
             <match url="^(.*)$" ignoreCase="false" />
             <conditions logicalGrouping="MatchAll">
               <add input="{URL}" pattern="^/public/" ignoreCase="false" negate="true" />
             </conditions>
             <action type="Rewrite" url="/public/{R:1}" />
         </rule>
        </rules>
     </rewrite>
    </system.webServer>
</configuration>

Save it as web.config and upload it to the website's wwwroot directory.

Some programs have complex routing rules, and settings may still have loading issues. You can consider upgrading the host and switching to a Linux system, or submit a ticket for us to verify.