西部数码虚拟主机隐藏路由中的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对应的文件中即可

参考:https://blog.csdn.net/qq_36129701/article/details/82687349

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值