zoukankan      html  css  js  c++  java
  • ThinkPHP5 Apache / IIs环境下 URL重写

    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>
    

    查看原文

  • 相关阅读:
    linux 下面 opcache 拓展
    php中函数前加&符号的作用分解
    apache 设置404页面
    nginx 环境搭建使用之入门
    curl获取http请求的状态码
    js打开新的窗体不被浏览器阻止
    YII 框架使用之——创建应用
    Yii 框架创建自己的 web 应用
    PHP中CURL方法curl_setopt()函数的一些参数
    Linux的学习--使用PuTTY
  • 原文地址:https://www.cnblogs.com/ovim/p/12172586.html
Copyright © 2011-2022 走看看