美文网首页
tp5部署空间/服务器/导致访问任何地址都只显示首页

tp5部署空间/服务器/导致访问任何地址都只显示首页

作者: LauEl | 来源:发表于2018-09-21 09:08 被阅读343次

thinkphp5写的项目,部署到Linux环境下,不管访问那个方法,都强制跳转到Index/index方法。

第一种方法:

修改Nginx的配置,大家可以参考下面:

location ~ \.php {
   fastcgi_pass   127.0.0.1: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;
}
location / { #去掉$
   if ( -f $request_filename) {
       break;
   }
   if ( !-e $request_filename) {
       rewrite ^(.*)$ /index.php/$1 last;
       break;
   }
   #新增
   try_files $uri $uri/ /index.php?$query_string;
}

第二种方法:

如果你的服务器是Apache,那么修改更目录下的 .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>

如果上面两种方法都不管用,那么使用第三种方法。
修改项目配置 config.php 中的 pathinfo_fetch 在末尾添加上 REQUEST_URI

// 兼容PATH_INFO获取
'pathinfo_fetch' => ['ORIG_PATH_INFO', 'REDIRECT_PATH_INFO', 'REDIRECT_URL', 'REQUEST_URI'],

如果还是不能只能使用终极绝招试试了..

修改更目录下的 .htaccess

万能兼容模式...

<IfModule mod_rewrite.c>
Options +FollowSymlinks -Multiviews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?s=$1 [QSA,PT,L]
</IfModule>

相关文章

网友评论

      本文标题:tp5部署空间/服务器/导致访问任何地址都只显示首页

      本文链接:https://www.haomeiwen.com/subject/iqtanftx.html