yii 隱藏index.php的方法

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

yii 隱藏index.php的方法

本教程操作環境:linux5.9.8系統、PHP5.6版,該方法適用于所有品牌電腦。

推薦:《PHP視頻教程

Yii 隱藏 index.php(Apache + nginx)

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

立即學習PHP免費學習筆記(深入)”;

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

2.1、Apache 配置

同時還要在index.php同級目錄下新建.htaccess文件

#表示開啟重寫引擎 RewriteEngine?on #請求的文件或路徑是不存在的,如果文件或路徑存在將返回已經存在的文件或路徑 RewriteCond?%{REQUEST_FILENAME}?!-f RewriteCond?%{REQUEST_FILENAME}?!-d RewriteRule?.?index.php

.htaccess文件解釋

概述來說,htaccess文件是Apache服務器中的一個配置文件,它負責相關目錄下的網頁配置。?

通過htaccess文件,可以幫我們實現:網頁301重定向、自定義404錯誤頁面、改變文件擴展名、 允許/阻止特定的用戶或者目錄的訪問、禁止目錄列表、配置默認文檔等功能。

2.2、nginx 配置

① nginx.conf 配置

worker_processes??1; events?{ ????worker_connections??1024; } http?{ ????include???????mime.types; ????default_type??application/octet-stream; ????sendfile????????on; ????keepalive_timeout??65; ????fastcgi_connect_timeout?300; ????fastcgi_send_timeout?300; ????fastcgi_read_timeout?300; ????fastcgi_buffer_size?128k; ????fastcgi_buffers?4?128k; ????fastcgi_busy_buffers_size?256k; ????fastcgi_temp_file_write_size?256k; ????gzip?on; ????gzip_min_length??1k; ????gzip_buffers?????4?32k; ????gzip_http_version?1.1; ????gzip_comp_level?2; ????gzip_types???????text/plain?application/x-JavaScript?text/css?application/xml; ????gzip_vary?on; ????gzip_disable?"MSIE?[1-6]."; ????server_names_hash_bucket_size?128; ????client_max_body_size?????100m;? ????client_header_buffer_size?256k; ????large_client_header_buffers?4?256k; ????server?{ ????????listen???????80; ????????server_name??localhost; ????????#你的項目根目錄 ????????root???"D:/Program?Files/phpStudy/WWW"; ????????location?/?{ ????????????index??index.html?index.htm?index.php?l.php; ???????????autoindex??off; ????????} ????????error_page???500?502?503?504??/50x.html; ????????location?=?/50x.html?{ ????????????root???html; ????????} ????????location?~?.php(.*)$??{ ????????????#你的項目根目錄 ????????????root???"D:/Program?Files/phpStudy/WWW"; ????????????fastcgi_pass???127.0.0.1:9000; ????????????fastcgi_index??index.php; ????????????fastcgi_split_path_info??^((?U).+.php)(/?.+)$; ????????????fastcgi_param??SCRIPT_FILENAME??$document_root$fastcgi_script_name; ????????????fastcgi_param??PATH_INFO??$fastcgi_path_info; ????????????fastcgi_param??PATH_TRANSLATED??$document_root$fastcgi_path_info; ????????????include????????fastcgi_params; ????????} ????} ????include?vhosts.conf; }

② vhosts.conf 配置

server?{ ????????listen???????80; ????????#你的虛擬主機名 ????????server_name??www.luluqi.com?; ????????#虛擬主機根目錄 ????????root???"D:/Program?Files/phpStudy/WWW/luluyii/web"; ????????location?/?{ ????????????index??index.php?index.html?index.htm; ????????????#nginx?ignore?index.php ????????????if?(!-e?$request_filename){?? ??????????????rewrite?^/(.*)?/index.php?last;?? ????????????}???? ????????} ????????location?~?.php(.*)$?{ ????????????fastcgi_pass???127.0.0.1:9000; ????????????fastcgi_index??index.php; ????????????fastcgi_split_path_info??^((?U).+.php)(/?.+)$; ????????????fastcgi_param??SCRIPT_FILENAME??$document_root$fastcgi_script_name; ????????????fastcgi_param??PATH_INFO??$fastcgi_path_info; ????????????fastcgi_param??PATH_TRANSLATED??$document_root$fastcgi_path_info; ????????????include????????fastcgi_params; ????????} ???????? }

更多編程相關知識,請訪問:PHP視頻教程!!

? 版權聲明
THE END
喜歡就支持一下吧
點贊14 分享