当前位置:Gxlcms > php框架 > yii 隐藏index.php的方法

yii 隐藏index.php的方法

时间:2021-07-01 10:21:17 帮助过:49人阅读

yii隐藏index.php的方法:首先在配置文件main.php中添加urlManager;然后在index.php同级目录下新建.htaccess文件;最后配置nginx.conf和vhosts.conf即可。

本教程操作环境:linux5.9.8系统、PHP5.6版,该方法适用于所有品牌电脑。

推荐:《PHP视频教程》

Yii 隐藏 index.php(Apache + nginx)

1、在配置文件 main.php 中添加

  1. 'urlManager' => [//用于URL路径化'enablePrettyUrl' => true,//指定是否在URL在保留入口脚本
  2. index.php'showScriptName' => false,],

2.1、Apache 配置

同时还要在index.php同级目录下新建.htaccess文件

  1. #表示开启重写引擎
  2. RewriteEngine on
  3. #请求的文件或路径是不存在的,如果文件或路径存在将返回已经存在的文件或路径
  4. RewriteCond %{REQUEST_FILENAME} !-f
  5. RewriteCond %{REQUEST_FILENAME} !-d
  6. RewriteRule . index.php

.htaccess文件解释

概述来说,htaccess文件是Apache服务器中的一个配置文件,它负责相关目录下的网页配置。

通过htaccess文件,可以帮我们实现:网页301重定向、自定义404错误页面、改变文件扩展名、 允许/阻止特定的用户或者目录的访问、禁止目录列表、配置默认文档等功能。

2.2、nginx 配置

① nginx.conf 配置

  1. worker_processes 1;
  2. events {
  3. worker_connections 1024;
  4. }
  5. http {
  6. include mime.types;
  7. default_type application/octet-stream;
  8. sendfile on;
  9. keepalive_timeout 65;
  10. fastcgi_connect_timeout 300;
  11. fastcgi_send_timeout 300;
  12. fastcgi_read_timeout 300;
  13. fastcgi_buffer_size 128k;
  14. fastcgi_buffers 4 128k;
  15. fastcgi_busy_buffers_size 256k;
  16. fastcgi_temp_file_write_size 256k;
  17. gzip on;
  18. gzip_min_length 1k;
  19. gzip_buffers 4 32k;
  20. gzip_http_version 1.1;
  21. gzip_comp_level 2;
  22. gzip_types text/plain application/x-javascript text/css application/xml;
  23. gzip_vary on;
  24. gzip_disable "MSIE [1-6].";
  25. server_names_hash_bucket_size 128;
  26. client_max_body_size 100m;
  27. client_header_buffer_size 256k;
  28. large_client_header_buffers 4 256k;
  29. server {
  30. listen 80;
  31. server_name localhost;
  32. #你的项目根目录
  33. root "D:/Program Files/phpStudy/WWW";
  34. location / {
  35. index index.html index.htm index.php l.php;
  36. autoindex off;
  37. }
  38. error_page 500 502 503 504 /50x.html;
  39. location = /50x.html {
  40. root html;
  41. }
  42. location ~ \.php(.*)$ {
  43. #你的项目根目录
  44. root "D:/Program Files/phpStudy/WWW";
  45. fastcgi_pass 127.0.0.1:9000;
  46. fastcgi_index index.php;
  47. fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
  48. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  49. fastcgi_param PATH_INFO $fastcgi_path_info;
  50. fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
  51. include fastcgi_params;
  52. }
  53. }
  54. include vhosts.conf;
  55. }

② vhosts.conf 配置

  1. server {
  2. listen 80;
  3. #你的虚拟主机名
  4. server_name www.luluqi.com ;
  5. #虚拟主机根目录
  6. root "D:/Program Files/phpStudy/WWW/luluyii/web";
  7. location / {
  8. index index.php index.html index.htm;
  9. #nginx ignore index.php
  10. if (!-e $request_filename){
  11. rewrite ^/(.*) /index.php last;
  12. }
  13. }
  14. location ~ \.php(.*)$ {
  15. fastcgi_pass 127.0.0.1:9000;
  16. fastcgi_index index.php;
  17. fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
  18. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  19. fastcgi_param PATH_INFO $fastcgi_path_info;
  20. fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
  21. include fastcgi_params;
  22. }
  23. }

更多编程相关知识,请访问:编程入门!!

以上就是yii 隐藏index.php的方法的详细内容,更多请关注gxlcms其它相关文章!

人气教程排行