PHP开发笔记(三)关于PHP伪静态的问题总结

Apache

第一个问题就是关于PHPStudy集成Apache环境下5.5版本以上”No input file specified“问题。

针对TP5框架,以下是.htaccess文件的配置,PHP 5.5版本以下可以正常使用。

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

然而上述配置文件切换到5.6版本以上就不可使用,直接报错“No input file specified”。修改成以下配置即可正常访问。

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

Nginx 

接下来再说一下TP5版本在nginx环境下支持PATHINFO模式和隐藏index.php的方法,本例是在centos7.0版本、nginx1.4.4版本下操作的,配置代码如下。我是直接在nginx.conf文件中进行配置的。

server {
            listen       80;
            server_name  www.abc.com;
            root  /weixin/public;
            index index.php;
            #隐藏index.php
            location / {
                  if (!-e $request_filename) {
                       #一级目录
                       # rewrite ^/(.*)$ /index.php/$1 last;
                       #二级目录
                       rewrite ^/(.*)$ /index.php/$1 last;
                     }  
            }
            location ~ .php($|/) {
                    fastcgi_pass localhost:9000;
                    fastcgi_index index.php;
            fastcgi_split_path_info ^(.+.php)(.*)$;  
            fastcgi_param   PATH_INFO $fastcgi_path_info;  
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name; 
                    include  fastcgi_params;
            }
            access_log  logs/aicaiche.access.log  main;
    }
原文地址:https://www.cnblogs.com/zhengluwei/p/8214006.html