虚拟空间iis环境下如何隐藏index.PHP
网上好多教程都是说要改iis环境什么的,但问题是,我只是虚拟空间啊,别人又不会帮你改iis什么的
弄了一天,头都炸了,后来无意间看到一个帖子,配置web.config。瞬间就通透了
就在tp5根目录下写了个config文件。
好了屁话不多说了,直接上代码
自己创建一个web.config文件,代码如下
<?xml version=”1.0″?>
<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>
</system.webServer>
</configuration>
 
1、然后tp5入口文件index添加绑定模块来隐藏模块:define(‘BIND_MODULE’,’index’);
2.在application\index\index\controller 添加 Error.php 作为空控制器
代码如下:
<?php
namespace app\index\controller;
use think\Controller;
class Error extends Controller
{
public function index()
{
//header(“HTTP/1.0 404 Not Found”);//使HTTP返回404状态码
//$this->redirect(url(‘index/index/index’)); exit;//返回主页
header( “HTTP/1.1 301 Moved Permanently” ) ;
header(“Location:http://show.millionser.com”);
}
}
3.在application\index\index\controller 修改index.php 作为空操作方法:
public function _empty()
{
header( “HTTP/1.1 301 Moved Permanently” ) ;
header(“Location:http://show.millionser.com”);
//header(“HTTP/1.0 404 Not Found”);//使HTTP返回404状态码
//$this->redirect(url(‘index/index/index’)); exit;//返回主页
}
(文章今日已有 1 人访问,总访问量 7 ::>_<::)