nginx url自動加斜杠問題


一、首先對比說明Nginx以下兩個現象:

1. 訪問的uri最后帶斜杠

  http://localhost/product/    >>>>  查找 product下的index頁面,存在就返回;不存在且未開啟自動索引目錄選項(指令是:autoindex on),則報403錯誤

2. 訪問的uri最后不帶斜杠

  http://localhost/product     >>>>  查找product文件,存在就返回;若存在product的文件夾,會產生301跳轉,且自動將uri補全為http://localhost/product/ ,跳轉的域名由server_name_in_redirect 指令控制(下文介紹)

二、server_name_in_redirect 指令配置

1、server_name_in_redirect on ,URL 重定向為: server_name 中的第一個域名 + 目錄名 + /;例如 配置文件中 server_name  www.baidu.com;  則http://localhost/product   時會重定向到http://www.baidu.com/product/(這是個坑)
2、server_name_in_redirect off (默認值)URL 重定向為: 原 URL 中的域名 + 目錄名 + /。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM