全网整合营销服务商

电脑端+手机端+微信端=数据同步管理

免费咨询热线:15617636856

郑州网站建设

当前位置: 首页 > 188app金宝搏网 >>ThinkPHP框架的WEB系统隐藏index.php文件名大全

ThinkPHP框架的WEB系统隐藏index.php文件名大全

作者:郑州网站建设发布时间:2023-09-03 10:22:27查看次数:来源:网络文章数:

技术人员大都使用过大名鼎鼎的ThinkPHP的程序框架,使用PHP语言开发的CMS系统中采用TP框架的占绝大多数。然而,对于新手来说直接上手开发整站系统还是有难度的,可以考虑先从一些成熟的基于TP框架的CMS系统开始着手学习。在系统中一般会采用伪静态,那么就会少不了路由规则,不熟悉正则表达式的同学有可能搞不定一些URL显示问题,如:TP框架运行时默认路径运行方式,会显示index.php/路径,不管哪个目录都会包含index.php这个文件名,看起来不够大气,如何修改路由规则去掉这个文件名,就需要对.htaccess文件进行调整。

ThinkPHP框架的WEB系统隐藏index.php文件名大全(图1)

以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>

如果你使用的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;
        }
}


站内文章:均为188bet博彩体育app下载方式 各部门原创内容如需转载请著名本文网站链接://www.mcissock.com/new/24512.html未经允许转载要受法律责任,如需转载请联系269247937@qq.com


[ThinkPHP框架的WEB系统隐藏index.php文件名大全]

本文链接://www.mcissock.com/new/24512.html
tags:隐藏index.phpTP不显示index.php文件名
网页是否收录:
188app金宝搏网 在线咨询

您的项目需求

*请认真填写需求信息,我们会在24小时内与您取得联系。

  • 返回顶部
  • 15617636856
  • QQ在线
  • 微信二维码
0
Baidu
map