thibkphp5 改好.htaccess 后依旧 模块不存在 的解决方法!

隐藏入口index.php的整了好久 主要是phpstudy的.htaccess跟thinkphp5文档的写法不一样所导致的 

所以记录下来引以为戒。

Apache为例,需要在入口文件的同级(public目录下)添加.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>

如果用的phpstudy,规则如下:

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

接下来就可以使用下面的URL地址访问了

 
  1. http://tp5.com/index/index/index

  2. http://tp5.com/index/index/hello

如果你使用的apache版本使用上面的方式无法正常隐藏index.php,可以尝试使用下面的方式配置.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>

如果是Nginx环境的话,可以在Nginx.conf中添加:

 
location / { // …..省略部分代码

if (!-e $request_filename) {

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

break;

}

}

猜你喜欢

转载自blog.csdn.net/wanganji5252/article/details/81293082