TP5框架 《隐藏入口文件 index.php》

版权声明:本文为博主原创文章,转载请注明原文出处! https://blog.csdn.net/qq_23375733/article/details/86573120

可以通过URL重写隐藏应用的入口文件index.php,下面是相关服务器的配置参考:

[ Apache ]

  1. httpd.conf配置文件中加载了mod_rewrite.so模块
  2. AllowOverride None 将None改为 All
  3. 把下面的内容保存为.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 ]

 location / { // …..省略部分代码
   if (!-e $request_filename) {
       rewrite  ^(.*)$  /index.php?s=/$1  last;
       break;
    }
 }

其实内部是转发到了ThinkPHP提供的兼容URL,利用这种方式,可以解决其他不支持PATHINFO的WEB服务器环境。

如果你的应用安装在二级目录,Nginx的伪静态方法设置如下,其中youdomain是所在的目录名称。

location /youdomain/ {
    if (!-e $request_filename){
        rewrite  ^/youdomain/(.*)$  /youdomain/index.php?s=/$1  last;
    }
}

#比如我域名下有 central 这个项目,那么配置可以参考以下来写
location /central/ {
   if (!-e $request_filename){
      rewrite  ^/central/public/(.*)$  /central/public/index.php?s=/$1  last;
   }
}

猜你喜欢

转载自blog.csdn.net/qq_23375733/article/details/86573120
今日推荐