Zuletzt aktiv 6 months ago

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

timmy hat die Gist bearbeitet 6 months ago. Zu Änderung gehen

1 file changed, 15 insertions

nginx_root_redirect.conf(Datei erstellt)

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