Thinkphp5-隐藏入口文件index.php(URL重写)

apache修改

1.加载httpd.conf配置文件中mod_rewrite.so模块:

打开httpd.conf配置文件,找到以下扩展 , 将其前面的#号去掉 , 重启apache

LoadModule rewrite_module modules/mod_rewrite.so

2.修改httpd-vhosts.conf配置文件

将AllowOverride None 的None改为 All

3.搜索DocumentRoot 将根目录设置成你的入口文件所在目录

image.png

4.修改.htaccess文件

把下面的内容保存为.htaccess文件放到应用入口文件的同级目录下,就在public目录

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

5.重启Apache服务器

(如果是其他服务器,可参阅官方手册 URL重写

Nginx 修改

1.找到对应的网站配置文件nginx.conf(一般位于 /etc/nginx/nginx.conf)

2.

location / {
    root html/dddai/public/;
    index index.php index.html;
    #主要是这句
    try_files $uri /index.php?$uri;
}

以下写法为特殊情况, 项目放在prosys文件夹下

location /prosys/ {
    index  index.html index.htm index.php;
    if (!-e $request_filename){
        rewrite  ^/prosys/(.*)$  /prosys/index.php?s=$1  last;
    }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容