搜索

首页  >  问答  >  正文

thinkphp nginx配置rewrite,地址会多出个.php

thinkphp nginx配置rewrite,地址会多出个.php
,http://localhost:7080/.php?m=...
nginx配置文件
server
{

1

2

3

4

5

6

<code>    listen 80;

    #listen [::]:80;

    server_name localhost 192.168.150.79 doc.mall.com;

    index index.html index.htm index.php default.html default.htm default.php;

    root  /data/www/wwwroot/mall_doc;

</code>

include none.conf;

1

2

3

4

5

6

7

8

9

<code>    #error_page   404   /404.html;

    location / {

            if (!-e $request_filename)

    {

            rewrite ^/index.php(.*)$ /index.php?s= last;

            rewrite ^(.*)$ /index.php?s= last;

            rewrite ^/(.*)$ /index.php/;

    }

    }</code>

location ~ .php {

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

<code>            fastcgi_pass  unix:/tmp/php-cgi.sock;

            fastcgi_index index.php;

            include fastcgi.conf;

            include fastcgi_params;

            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

            set $path_info "";

            set $real_script_name $fastcgi_script_name;

            if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {

                    set $real_script_name ;

                    set $path_info ;

            }

            fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;

            fastcgi_param SCRIPT_NAME $real_script_name;

            fastcgi_param PATH_INFO $path_info;

    }

 

    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$

    {

            expires      30d;

    }

 

    location ~ .*\.(js|css)?$

    {

            expires      12h;

    }

 

access_log  /data/www/wwwlogs/doc.mall.access_log;</code>

}

rewrite ^/index.php(.*)$ /index.php?s=$1 last;
rewrite ^(.*)$ /index.php?s=$1 last;
rewrite ^/(.*)$ /index.php/$1;
这三种方式都试过了
'URL_MODEL' => 2,
php版本为PHP 7.1.5

nginx版本为:nginx/1.12.0

大家有么碰到这种情况?
php版本在5.6.9上是正常访问

为情所困为情所困2846 天前928

全部回复(2)我来回复

  • 某草草

    某草草2017-06-16 09:20:37

    之前我配置THINKCMF的时候也出现过这个问题

    1

    2

    3

    4

    5

    6

    7

    8

    9

    <code>    if(!defined('_PHP_FILE_')) {

            if(IS_CGI) {

                //CGI/FASTCGI模式下

                $_temp  = explode('.php',$_SERVER['PHP_SELF']);

                define('_PHP_FILE_',    rtrim(str_replace($_SERVER['HTTP_HOST'],'',$_temp[0].'.php'),'/'));

            }else {

                define('_PHP_FILE_',    rtrim($_SERVER['SCRIPT_NAME'],'/'));

            }

        }</code>

    后来找到问题是这个$_SERVER['SCRIPT_NAME'] 常量中的路径出现问题有2个解决放过
    1.你修改常量中的数据
    2.使用APACHE
    目前就想到这2个方法
    另外可以关注我的博客 PHP程序员学习笔记

    回复
    0
  • 巴扎黑

    巴扎黑2017-06-16 09:20:37

    雷雷

    回复
    0
  • 取消回复