ThinkPHP路由去掉隐藏URL中的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>
View Code

phpstudy规则

1、确认你的apache开启rewrite模块、

2、修改官方文件最后一行

RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1]

apache版本使用上边的方式无法正常隐藏index.php 可以尝试使用下边的方式配置.htaccess文件:

1、确认你的apache开启rewrite模块、

2、修改官方文件最后一行,在/$1前边加一个 ? (注意英文格式半角)

 RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L]

 Nginx环境,可以在Nginx.conf中添加:

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

 

posted @ 2019-01-17 09:24  PHP菜鸟-小菜鸡  阅读(2585)  评论(0)    收藏  举报
Top