Naposledy aktivní 6 months ago

此 Nginx 設定檔案示範如何將根目錄請求自動轉向至指定路徑(如 /target-path 或 /dashboard),使用 301 永久導向,並包含註解說明設置位置及轉向行為。

Revize 7b29a82818525e9cec6c28bab10d7fb486fa0665

nginx_root_redirect.conf Raw
1# --- 根目錄自動導向設定範例 ---
2# 若網址是根目錄,自動 301 轉到 /target-path
3# 301 是永久導向(SEO 友善),若只想暫時導向,請改成 302
4# 自訂路徑前記得加上斜線(/),不然 Nginx 會報語法錯誤
5# 請貼在任何 allow/deny 設定之後
6
7if ($request_uri = "/") {
8 return 301 /target-path;
9}
10
11# --- 根目錄自動導向設定範例 ---
12# 若網址是根目錄,自動 301 轉到 /dashboard
13if ($request_uri = "/") {
14 return 301 /dashboard;
15}
16