隐藏index.php

可以去掉URL地址里面的入口文件index.php,但是需要额外配置WEB服务器的重写规则。

Apache为例,需要在入口文件的同级添加.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>

如果用的phpstudy,规则如下:

<IfModule mod_rewrite.c>
Options +FollowSymlinks -Multiviews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1]
</IfModule>

如果index.php文件存放在public中,规则如下:

<IfModule mod_rewrite.c>
Options +FollowSymlinks -Multiviews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ public/index.php [L,E=PATH_INFO:$1]
</IfModule>

接下来就可以使用下面的URL地址访问了

http://tp5.com/index/index/index
http://tp5.com/index/index/hello

如果你使用的apache版本使用上面的方式无法正常隐藏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>

如果是Nginx环境的话,可以在Nginx.conf中添加:

location / { // …..省略部分代码
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
break;
}
}
vhosts-conf
server {
        listen       80;
        server_name  xhb.com www.xhb.com;
        root   "F:/project/xhb";
        location / {
            index  index.html index.htm index.php;
            if (!-e $request_filename) {
        rewrite  ^(.*)$  /index.php?s=/$1  last;
        break;
    }
            #autoindex  on;
        }
        location ~ \.php(.*)$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }
}

												

ThinkPHP5 隐藏index.php问题的更多相关文章

  1. [转]ThinkPHP5 隐藏index.php问题

    ThinkPHP5 隐藏index.php问题 Apache,修改.htaccess文件 ----------------------------------------------------- R ...

  2. ngnix配置thinkphp5隐藏index.php的方法亲测有效

    在需要访问的域名的conf文件中,比如 vim /etc/nginx/.com.conf location / { // …..省略部分代码 if (!-e $request_filename) { ...

  3. thinkphp5, 隐藏index.php

    tp5官网手册里的代码有误, 注意防坑, 正确的应该是: 修改.htaccess文件: <IfModule mod_rewrite.c> Options +FollowSymlinks R ...

  4. ThinkPHP5 隐藏接口里面的index.php

    隐藏index.php 官方介绍是这样的:http://www.kancloud.cn/thinkphp/thinkphp5_quickstart/145250 可以去掉URL地址里面的入口文件ind ...

  5. thinkphp5 隐藏前台入口文件index.php 后台入口文件admin.php不隐藏

    情景:应用目录下有两个模块 admin(后台) 和 home(前台) 需求:1.访问前台(home)时隐藏index.php  即 域名/home/前台控制器/前台控制器里的方法 这样的访问模式 2. ...

  6. CI 框架隐藏index.php-ubuntu

    和朋友在做一个小网站,用到了CI框架,之前测试都是在windows上,隐藏index.php也相对比较简单.但服务器是ubuntu系统,需要配置一下,根据网上看到的一些教程,结合自己电脑的特点,记录步 ...

  7. thinkphp中redirect重定向后隐藏index.php

    首先,.htaccess文件要配置好隐藏index.php.系统默认生成的就行. 然后,也是最关键的一部,要在Application/Home/Conf里的config.php文件中增加如下配置: & ...

  8. Yii 1.1 URL两个笔记 同时支持PATH于GET路由和隐藏index.php

    同时支持PATH于GET格式路由(修改框架文件 简直坑) framework/web/CUrlManager.php parseUrl方法 第一行判断修改成 if($this->getUrlFo ...

  9. tp5 隐藏index.php 邓士鹏

    tp5 隐藏index.php ------------------------------------------------------------------------------------ ...

随机推荐

  1. PCB之PASTE助焊层和SOLDER阻焊层

    1.PASTE为焊接层,用于SMT贴片元件的焊接,对应的图形为钢网(钢网上的小孔): 2.SOLDER为阻焊层,它代表的是绿油的涂抹区域,且为负片输出(负片输出指的是图形以外的区域为有效区域): PA ...

  2. [清华集训2017]榕树之心[树dp]

    题意 题目链接 分析 首先解决 \(subtask3\) ,我们的策略就是进入子树,然后用其它子树来抵消,注意在子树内还可以抵消. 可以转化为此模型:有一个数列 \(a\) ,每次我们可以选定两个值 ...

  3. PHP 设置调试工具XDebug PHPStorm IDE

    先下载PHP扩展Xdebug https://xdebug.org, 可以复制自己的phpinfo粘贴到https://xdebug.org/wizard.php中, 会生成需要下载的版本, php. ...

  4. GlusterFS分布式存储集群部署记录-相关补充

    接着上一篇Centos7下GlusterFS分布式存储集群环境部署记录文档,继续做一些补充记录,希望能加深对GlusterFS存储操作的理解和熟悉度. ======================== ...

  5. Linux运维笔记-日常操作命令总结(3)

    文本操作:sed sed是一个很好的文件处理工具,本身是一个管道命令,主要是以行为单位进行处理,可以将数据行进行替换.删除.新增.选取等特定工作. sed命令行格式为: sed [-nefri] ‘c ...

  6. 牛客OI赛制测试赛-序列-模拟

    哇这道题好坑啊,可能是我太菜了 题意就是叫把一个连续序列分成K组,使得每个组的和都相等 我最开始的想法是由于要分成K组,那我们知道,每组一定有sum(a[i])/k这样我们只需要每次当num==sum ...

  7. Map获取key值

    有两种方法 public static void test4(){ Map<String, Object> map = new HashMap<>(); map.put(&qu ...

  8. 四则运算C语言程序

    #include<stdio.h> #include<Windows.h> #include<time.h> void main() { int a, b, c, ...

  9. idea 设置注释

    idea和eclipse的注释还是有一些差别的. idea: 类头注释:打开file->setting->Editor->Filr and Code Templates->In ...

  10. Leetcode——66.加一

    @author: ZZQ @software: PyCharm @file: leetcode66_加一.py @time: 2018/11/29 16:07 要求:给定一个由整数组成的非空数组所表示 ...