thinkphp5 Apache / IIs环境下 URL重写

发布时间:2020-07-10 18:26:04 作者:lb沫
来源:网络 阅读:2181

好像thinkPHP5新版本 隐藏index.php隐藏index.php 都写好了
public 隐藏
独立主机可以直接把根目录指向public下
虚拟主机可以把public下的index.php放到根目录

public下原有index.php
// 定义应用目录
define('APP_PATH', __DIR__ . '/../application/');
// 加载框架引导文件
require __DIR__ . '/../thinkphp/start.php';
放到根目录下的index.php
// 定义应用目录
define('APP_PATH', __DIR__ . '/application/');
// 加载框架引导文件
require __DIR__ . '/thinkphp/start.php';

Apache下隐藏index.php
tp5好像都给写好了.htaccess文件 index.php都给隐藏掉了
如果是index.php移到根目录了只需要把.htaccess文件放到根目录下

其中代码
<IfModule mod_rewrite.c>
  Options +FollowSymlinks -Multiviews
  RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>

iis下隐藏
有的主机后台有URL Rewrite直接写规则就可以了

没有直接在根目录创建web.config

其中代码
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="WPurls" enabled="true" stopProcessing="true">
                    <match url=".*" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php/{R:0}" />
                </rule>
            </rules>
        </rewrite>

        <defaultDocument>
            <files>
                <clear />
                <add value="index.php" />
                <add value="index.html" />
            </files>
        </defaultDocument>
    </system.webServer>
</configuration>
推荐阅读:
  1. URL 如何发送 GET 请求调用云服务器 ECS API
  2. 什么是基于URL发起HTTP/HTTPS GET的请求结构

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

url 重写 环境下

上一篇: Web前端面试指导(五):掌握面试技巧,让面试变得轻松

下一篇:CentOS7.5修改系统语言为简体中文

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》