西部数码虚拟主机隐藏路由中的index.php

虚拟主机和服务器部署起来还是有所差别,使用thinkcmf和fastadmin开发的项目,放到虚拟主机上,没有直接权限将项目主域名指向public目录下,而客户又偏要使用主域名,于是只有将wwwroot目录当做public目录,将项目重新分开布局,布局好之后发现路由出现问题,必须输入index.php才能将页面显示,这就使得体验不佳,于是需要将index.php进行隐藏。 在虚拟主机中找到为静态设置,选择shopex,在wwwroot目录中生成一个web.config文件,需要将以下代码覆盖原来web.config中的代码

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
          <rewrite>

 <rules>

 <rule name="OrgPage" stopProcessing="true">

 <match url="^(.*)$" />

 <conditions logicalGrouping="MatchAll">

 <add input="{HTTP_HOST}" pattern="^(.*)$" />

 <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />

 <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />

 </conditions>

 <action type="Rewrite" url="index.php/{R:1}" />

 </rule>

 </rules>

 </rewrite>
        <directoryBrowse enabled="false" />
        <defaultDocument>
            <files>
                <clear />
                <add value="index.asp" />
                <add value="index.aspx" />
                <add value="index.php" />
                <add value="index.html" />
                <add value="Default.htm" />
                <add value="Default.asp" />
                <add value="index.htm" />
                <add value="Default.aspx" />
                <add value="index.shtml" />
            </files>
        </defaultDocument>
        <httpErrors>
            <remove statusCode="404" subStatusCode="-1" />
            <error statusCode="404" prefixLanguageFilePath="" path="/404.html" responseMode="ExecuteURL" />
        </httpErrors>
        <security> 
            <requestFiltering allowDoubleEscaping="true"></requestFiltering> 
        </security>
    </system.webServer>
</configuration>

打开网站测试,发现将index.php隐藏了。
本文是将wwwroot目录当做public目录进行布局的,如果你的项目是其他布局,只需要将生成的web.config文件放到public对应的文件中即可

猜你喜欢

转载自blog.csdn.net/qq_36129701/article/details/82687349
今日推荐