thinkphp5 url访问问题

http://localhost:8888/thinkphp_5.0.20/public/index.php

1、上面链接能访问,但是如下链接不能访问,刚下载的源码

http://localhost:8888/thinkphp_5.0.20/public/index.php/index/Index/index

2、如何让url能够简化访问,比如如下,不用加index.php
http://localhost:8888/thinkphp_5.0.20/index/index/index

阅读 2.5k
2 个回答

按服务器器类型进行下面的配置可以忽略index.php
Apache :public下的.htaccess配置:

<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 的Nginx.conf:

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

这是我的配置文件,仅供参考:

  server {
    server_name www.phpyd.com;
    access_log /data/wwwlogs/access_myfast.log combined;
    root /data/wwwroot/myfastadmin/public;
    index index.html index.htm index.php;
    #error_page 404 /404.html;
    #error_page 502 /502.html;
    location /nginx_status {
      stub_status on;
      access_log off;
      allow 127.0.0.1;
      deny all;
    }
    location ~ [^/]\.php(/|$) {
      #fastcgi_pass 127.0.0.1:9000;
      fastcgi_pass unix:/dev/shm/php-cgi.sock;
      fastcgi_index index.php;
      include fastcgi.conf;

      fastcgi_split_path_info ^(.+\.php)(/.+)$;
      fastcgi_param   PATH_INFO   $fastcgi_path_info;
      fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
      expires 30d;
      access_log off;
    }
    location ~ .*\.(js|css)?$ {
      expires 7d;
      access_log off;
    }
    location ~ /\.ht {
      deny all;
    }
    location ~* \.(eot|ttf|woff|svg|otf)$ {
        add_header Access-Control-Allow-Origin *;
        add_header Access-Control-Allow-Headers X-Requested-With;
        add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
    }

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

/public/index.php/index/Index/index
不能访问,你打开调试模式,看看是报的什么错,是模块,还是控制器,还是操作不存在?

简化url的问题,请看url重写部分的文档。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
宣传栏