鍍金池/ 問答/PHP/ thinkphp5 url訪問問題

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能夠簡(jiǎn)化訪問,比如如下,不用加index.php
http://localhost:8888/thinkphp_5.0.20/index/index/index

回答
編輯回答
別逞強(qiáng)

/public/index.php/index/Index/index
不能訪問,你打開調(diào)試模式,看看是報(bào)的什么錯(cuò),是模塊,還是控制器,還是操作不存在?

簡(jiǎn)化url的問題,請(qǐng)看url重寫部分的文檔。

2017年3月7日 09:58
編輯回答
傲寒

按服務(wù)器器類型進(jìn)行下面的配置可以忽略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;
     }
  }
2017年12月5日 07:43