小編給大家分享一下yii如何隱藏index.php,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
yii隱藏index.php的方法:首先在配置文件main.php中添加urlManager;然后在index.php同級目錄下新建.htaccess文件;最后配置nginx.conf和vhosts.conf即可。
Yii 隱藏 index.php(Apache + nginx)
1、在配置文件 main.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;
}
}以上是“yii如何隱藏index.php”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。