fix(seo): real 404 for unknown paths + stop http:// redirect downgrade
- nginx: try_files ... =404 + error_page 404 /404.html (was falling back to /index.html, so every unknown path returned 200 + homepage = 145 phantom URLs / 167k impressions in GSC) - nginx: absolute_redirect off — TLS terminates at the proxy, so nginx saw scheme http and every directory redirect sent Location: http:// (2 hops) - nginx: complete the 13 legacy WordPress 301s (3 already existed), all targets now absolute https + trailing slash + percent-encoded = 1 hop - nginx: /armflex now points straight at /armaflex/ (was 2 hops) - scripts/verify-seo-routing.sh: one-command check of 404 / 301 / target h1 / sitemap. Local run against fresh dist: PASS=72 FAIL=0
This commit is contained in:
1 parent
b3705aa38f
commit
2bef9fa57a
2 files changed
+177
-12
No files matched your search
+72
-12
@@ -1,6 +1,15 @@
|
||||
# =====================================================================
|
||||
# Deal Plus Tech — nginx (EasyPanel / Docker, TLS terminated at proxy)
|
||||
#
|
||||
# กฎสำคัญ 2 ข้อของไฟล์นี้:
|
||||
# 1) absolute_redirect off; — TLS จบที่ proxy เราเห็นแค่ http ถ้าปล่อยให้ nginx
|
||||
# สร้าง Location แบบ absolute จะได้ http:// (scheme downgrade) ทุกครั้ง
|
||||
# ที่มี redirect ภายใน (เช่น /grilles -> /grilles/) = redirect chain 2 hop
|
||||
# 2) try_files ... =404 — ห้าม fallback ไป /index.html เด็ดขาด
|
||||
# (ของเดิมคืน 200 + หน้าแรกให้ทุก path ที่ไม่รู้จัก = ต้นเหตุ URL ผี 143 URL ใน GSC)
|
||||
# =====================================================================
|
||||
|
||||
# non-www -> www (301) — canonical host is www.dealplustech.co.th
|
||||
# =====================================================================
|
||||
server {
|
||||
listen 80;
|
||||
listen [::]:80;
|
||||
@@ -17,6 +26,12 @@ server {
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
# Location header แบบ relative — กัน http:// downgrade (ดูหมายเหตุหัวไฟล์)
|
||||
absolute_redirect off;
|
||||
|
||||
# 404 จริง + หน้า 404 ของ Astro (dist/404.html)
|
||||
error_page 404 /404.html;
|
||||
|
||||
# gzip
|
||||
gzip on;
|
||||
gzip_vary on;
|
||||
@@ -46,20 +61,64 @@ server {
|
||||
try_files $uri =404;
|
||||
}
|
||||
|
||||
# 301 redirect: old misspelled product slug (armflex -> armaflex)
|
||||
location = /armflex { return 301 /armaflex; }
|
||||
location = /armflex/ { return 301 /armaflex; }
|
||||
# Astro's 404 page — เข้าถึงได้เฉพาะผ่าน error_page
|
||||
location = /404.html {
|
||||
internal;
|
||||
}
|
||||
|
||||
# 301 redirects: legacy WordPress slugs -> current pages
|
||||
# (absolute https + percent-encoded targets: TLS ends at the proxy, so nginx sees http;
|
||||
# absolute URLs avoid an extra http->https hop and keep headers ASCII-only)
|
||||
location = /ท่อhdpe { return 301 https://www.dealplustech.co.th/%E0%B8%97%E0%B9%88%E0%B8%AD-hdpe/; }
|
||||
location = /ท่อhdpe/ { return 301 https://www.dealplustech.co.th/%E0%B8%97%E0%B9%88%E0%B8%AD-hdpe/; }
|
||||
location = /ระบบรั้วไวน์แมน-vineman-2 { return 301 https://www.dealplustech.co.th/%E0%B8%A3%E0%B8%B0%E0%B8%9A%E0%B8%9A%E0%B8%A3%E0%B8%B1%E0%B9%89%E0%B8%A7%E0%B9%84%E0%B8%A7%E0%B8%99%E0%B9%8C%E0%B9%81%E0%B8%A1%E0%B8%99/; }
|
||||
location = /ระบบรั้วไวน์แมน-vineman-2/ { return 301 https://www.dealplustech.co.th/%E0%B8%A3%E0%B8%B0%E0%B8%9A%E0%B8%9A%E0%B8%A3%E0%B8%B1%E0%B9%89%E0%B8%A7%E0%B9%84%E0%B8%A7%E0%B8%99%E0%B9%8C%E0%B9%81%E0%B8%A1%E0%B8%99/; }
|
||||
# -----------------------------------------------------------------
|
||||
# 301 redirects: legacy slugs -> current pages
|
||||
# เป้าต้องมี trailing slash เสมอ (canonical ของเว็บเป็น /path/) ไม่งั้นโดน
|
||||
# directory redirect ซ้ำอีก hop
|
||||
# absolute https + percent-encoded: ไม่ต้องพึ่ง scheme ที่ proxy ส่งมา และ log อ่านง่าย
|
||||
# -----------------------------------------------------------------
|
||||
|
||||
# สะกดผิดเดิม
|
||||
location = /armflex { return 301 https://www.dealplustech.co.th/armaflex/; }
|
||||
location = /armflex/ { return 301 https://www.dealplustech.co.th/armaflex/; }
|
||||
|
||||
# WordPress เดิม (GSC: 112,311 impressions รวม)
|
||||
location = /ท่อและข้อต่อpvc { return 301 https://www.dealplustech.co.th/%E0%B8%97%E0%B9%88%E0%B8%AD-upvc/; }
|
||||
location = /ท่อและข้อต่อpvc/ { return 301 https://www.dealplustech.co.th/%E0%B8%97%E0%B9%88%E0%B8%AD-upvc/; }
|
||||
|
||||
# หน้าเก่า "หัวจ่ายลม (กริล) หรือหน้ากากแอร์" = กริล ไม่ใช่ diffuser (ยืนยันจาก Wayback 2022-06-26)
|
||||
location = /หัวจ่ายลม-กริล { return 301 https://www.dealplustech.co.th/grilles/; }
|
||||
location = /หัวจ่ายลม-กริล/ { return 301 https://www.dealplustech.co.th/grilles/; }
|
||||
|
||||
location = /ท่อhdpe { return 301 https://www.dealplustech.co.th/%E0%B8%97%E0%B9%88%E0%B8%AD-hdpe/; }
|
||||
location = /ท่อhdpe/ { return 301 https://www.dealplustech.co.th/%E0%B8%97%E0%B9%88%E0%B8%AD-hdpe/; }
|
||||
|
||||
location = /ระบบรั้วไวน์แมน-vineman-2 { return 301 https://www.dealplustech.co.th/%E0%B8%A3%E0%B8%B0%E0%B8%9A%E0%B8%9A%E0%B8%A3%E0%B8%B1%E0%B9%89%E0%B8%A7%E0%B9%84%E0%B8%A7%E0%B8%99%E0%B9%8C%E0%B9%81%E0%B8%A1%E0%B8%99/; }
|
||||
location = /ระบบรั้วไวน์แมน-vineman-2/ { return 301 https://www.dealplustech.co.th/%E0%B8%A3%E0%B8%B0%E0%B8%9A%E0%B8%9A%E0%B8%A3%E0%B8%B1%E0%B9%89%E0%B8%A7%E0%B9%84%E0%B8%A7%E0%B8%99%E0%B9%8C%E0%B9%81%E0%B8%A1%E0%B8%99/; }
|
||||
|
||||
location = /ท่อไซเลอร์ { return 301 https://www.dealplustech.co.th/%E0%B8%97%E0%B9%88%E0%B8%AD-syler/; }
|
||||
location = /ท่อไซเลอร์/ { return 301 https://www.dealplustech.co.th/%E0%B8%97%E0%B9%88%E0%B8%AD-syler/; }
|
||||
|
||||
location = /ท่อsyler-เป็นท่อเหล็กกล้าclass-m { return 301 https://www.dealplustech.co.th/%E0%B8%97%E0%B9%88%E0%B8%AD-syler/; }
|
||||
location = /ท่อsyler-เป็นท่อเหล็กกล้าclass-m/ { return 301 https://www.dealplustech.co.th/%E0%B8%97%E0%B9%88%E0%B8%AD-syler/; }
|
||||
|
||||
location = /groove-coupling { return 301 https://www.dealplustech.co.th/%E0%B9%80%E0%B8%A1%E0%B9%87%E0%B8%81%E0%B8%81%E0%B8%A3%E0%B8%B9%E0%B9%8A%E0%B8%9F-%E0%B8%84%E0%B8%B1%E0%B8%9A%E0%B8%9B%E0%B8%A5%E0%B8%B4%E0%B9%89%E0%B8%87/; }
|
||||
location = /groove-coupling/ { return 301 https://www.dealplustech.co.th/%E0%B9%80%E0%B8%A1%E0%B9%87%E0%B8%81%E0%B8%81%E0%B8%A3%E0%B8%B9%E0%B9%8A%E0%B8%9F-%E0%B8%84%E0%B8%B1%E0%B8%9A%E0%B8%9B%E0%B8%A5%E0%B8%B4%E0%B9%89%E0%B8%87/; }
|
||||
|
||||
location = /ท่อพีพีอาร์ { return 301 https://www.dealplustech.co.th/%E0%B8%97%E0%B9%88%E0%B8%AD-ppr-thai-ppr/; }
|
||||
location = /ท่อพีพีอาร์/ { return 301 https://www.dealplustech.co.th/%E0%B8%97%E0%B9%88%E0%B8%AD-ppr-thai-ppr/; }
|
||||
|
||||
location = /ท่อพีพีอาร์ตราช้าง { return 301 https://www.dealplustech.co.th/%E0%B8%97%E0%B9%88%E0%B8%AD-ppr-scg/; }
|
||||
location = /ท่อพีพีอาร์ตราช้าง/ { return 301 https://www.dealplustech.co.th/%E0%B8%97%E0%B9%88%E0%B8%AD-ppr-scg/; }
|
||||
|
||||
# ชั่วคราว: ยังไม่มี hub "ฉนวนกันความร้อน" — เปลี่ยนเป้าเมื่อ hub ขึ้น (HANDOFF 2B)
|
||||
location = /ฉนวนหุ้มท่อ-pipe-insulation { return 301 https://www.dealplustech.co.th/%E0%B9%80%E0%B8%97%E0%B8%AD%E0%B8%A3%E0%B9%8C%E0%B9%82%E0%B8%A1%E0%B9%80%E0%B8%9A%E0%B8%A3%E0%B8%84-thermobreak/; }
|
||||
location = /ฉนวนหุ้มท่อ-pipe-insulation/ { return 301 https://www.dealplustech.co.th/%E0%B9%80%E0%B8%97%E0%B8%AD%E0%B8%A3%E0%B9%8C%E0%B9%82%E0%B8%A1%E0%B9%80%E0%B8%9A%E0%B8%A3%E0%B8%84-thermobreak/; }
|
||||
|
||||
location = /ระบบวาล์วเติมอากาศ-durgo-aavs { return 301 https://www.dealplustech.co.th/durgo-avvs/; }
|
||||
location = /ระบบวาล์วเติมอากาศ-durgo-aavs/ { return 301 https://www.dealplustech.co.th/durgo-avvs/; }
|
||||
|
||||
location = /ท่อระบายน้ำ-3-ชั้น-ไซเลนท { return 301 https://www.dealplustech.co.th/%E0%B8%97%E0%B9%88%E0%B8%AD-xy-lent/; }
|
||||
location = /ท่อระบายน้ำ-3-ชั้น-ไซเลนท/ { return 301 https://www.dealplustech.co.th/%E0%B8%97%E0%B9%88%E0%B8%AD-xy-lent/; }
|
||||
|
||||
location = /หัวจ่ายแอร์-ball-jet { return 301 https://www.dealplustech.co.th/%E0%B8%AB%E0%B8%B1%E0%B8%A7%E0%B8%88%E0%B9%88%E0%B8%B2%E0%B8%A2-ball-jet/; }
|
||||
location = /หัวจ่ายแอร์-ball-jet/ { return 301 https://www.dealplustech.co.th/%E0%B8%AB%E0%B8%B1%E0%B8%A7%E0%B8%88%E0%B9%88%E0%B8%B2%E0%B8%A2-ball-jet/; }
|
||||
|
||||
# Don't cache HTML
|
||||
location ~* \.html$ {
|
||||
expires -1;
|
||||
@@ -67,8 +126,9 @@ server {
|
||||
}
|
||||
|
||||
# Thai URL slugs (Astro file-based routing produces paths with UTF-8 chars)
|
||||
# =404: path ที่ไม่ตรง route ต้องคืน 404 ไม่ใช่หน้าแรก
|
||||
location / {
|
||||
try_files $uri $uri/ $uri.html /index.html;
|
||||
try_files $uri $uri/ $uri.html =404;
|
||||
}
|
||||
|
||||
# healthcheck
|
||||
|
||||
Executable
+105
@@ -0,0 +1,105 @@
|
||||
#!/usr/bin/env bash
|
||||
# =====================================================================
|
||||
# verify-seo-routing.sh — ตรวจ routing/redirect ของ dealplustech
|
||||
#
|
||||
# ใช้:
|
||||
# ./scripts/verify-seo-routing.sh # ตรวจ production
|
||||
# ./scripts/verify-seo-routing.sh http://127.0.0.1:8080 # ตรวจ nginx ในเครื่อง
|
||||
#
|
||||
# ตรวจ 4 อย่าง:
|
||||
# 1. unknown path ต้อง 404 (ไม่ใช่ 200 + หน้าแรก)
|
||||
# 2. legacy path ต้อง 301 ไปเป้าที่ถูก
|
||||
# 3. เป้าของ 301 ต้อง 200 + h1 ตรงสินค้า
|
||||
# 4. หน้าใน sitemap ต้อง 200 ทั้งหมด
|
||||
#
|
||||
# exit 1 ถ้ามีข้อไหนไม่ผ่าน
|
||||
# =====================================================================
|
||||
set -uo pipefail
|
||||
|
||||
BASE="${1:-https://www.dealplustech.co.th}"
|
||||
BASE="${BASE%/}"
|
||||
fail=0
|
||||
pass=0
|
||||
|
||||
ok() { pass=$((pass+1)); printf ' \033[32mPASS\033[0m %s\n' "$1"; }
|
||||
bad() { fail=$((fail+1)); printf ' \033[31mFAIL\033[0m %s\n' "$1"; }
|
||||
|
||||
code() { curl -s -o /dev/null -m 30 -w '%{http_code}' "$1"; }
|
||||
code_loc() { curl -s -o /dev/null -m 30 -w '%{http_code} %{redirect_url}' "$1"; }
|
||||
|
||||
echo "== 1. unknown path ต้อง 404 =="
|
||||
c=$(code "$BASE/asdfghjkl-test-404")
|
||||
[ "$c" = "404" ] && ok "unknown path -> $c" || bad "unknown path -> $c (ต้องเป็น 404)"
|
||||
|
||||
echo "== 2. legacy path -> 301 ไปเป้าที่ถูก =="
|
||||
# รูปแบบ: "old|expected-target" (ระบุ trailing slash ทั้งคู่)
|
||||
REDIRECTS=(
|
||||
"/armflex|/armaflex/"
|
||||
"/ท่อและข้อต่อpvc/|/ท่อ-upvc/"
|
||||
"/หัวจ่ายลม-กริล/|/grilles/"
|
||||
"/ท่อhdpe/|/ท่อ-hdpe/"
|
||||
"/ระบบรั้วไวน์แมน-vineman-2/|/ระบบรั้วไวน์แมน/"
|
||||
"/ท่อไซเลอร์/|/ท่อ-syler/"
|
||||
"/ท่อsyler-เป็นท่อเหล็กกล้าclass-m/|/ท่อ-syler/"
|
||||
"/groove-coupling/|/เม็กกรู๊ฟ-คับปลิ้ง/"
|
||||
"/ท่อพีพีอาร์/|/ท่อ-ppr-thai-ppr/"
|
||||
"/ท่อพีพีอาร์ตราช้าง/|/ท่อ-ppr-scg/"
|
||||
"/ฉนวนหุ้มท่อ-pipe-insulation/|/เทอร์โมเบรค-thermobreak/"
|
||||
"/ระบบวาล์วเติมอากาศ-durgo-aavs/|/durgo-avvs/"
|
||||
"/ท่อระบายน้ำ-3-ชั้น-ไซเลนท/|/ท่อ-xy-lent/"
|
||||
"/หัวจ่ายแอร์-ball-jet/|/หัวจ่าย-ball-jet/"
|
||||
)
|
||||
for row in "${REDIRECTS[@]}"; do
|
||||
old="${row%%|*}"; want="${row##*|}"
|
||||
read -r c loc <<<"$(code_loc "$BASE$old")"
|
||||
# เทียบ path ส่วนท้าย (ตัด scheme+host ออก) และยอมรับ percent-encoded
|
||||
got_path="$(python3 -c "import sys,urllib.parse as u;print(u.unquote(u.urlsplit(sys.argv[1]).path))" "$loc" 2>/dev/null)"
|
||||
if [ "$c" = "301" ] && [ "$got_path" = "$want" ]; then
|
||||
ok "$old -> $c $want"
|
||||
else
|
||||
bad "$old -> $c '${got_path:-?}' (ต้องการ 301 $want)"
|
||||
fi
|
||||
done
|
||||
|
||||
echo "== 3. เป้าปลายทางต้อง 200 + h1 ตรงสินค้า (ไม่ใช่หน้าแรก) =="
|
||||
TARGETS=("/ท่อ-upvc/" "/grilles/" "/ท่อ-hdpe/" "/ระบบรั้วไวน์แมน/" "/ท่อ-syler/"
|
||||
"/เม็กกรู๊ฟ-คับปลิ้ง/" "/ท่อ-ppr-thai-ppr/" "/เทอร์โมเบรค-thermobreak/"
|
||||
"/durgo-avvs/" "/ท่อ-ppr-scg/" "/ท่อ-xy-lent/" "/หัวจ่าย-ball-jet/" "/armaflex/")
|
||||
HOME_H1="ระบบน้ำ คุณภาพสูง"
|
||||
for t in "${TARGETS[@]}"; do
|
||||
body="$(curl -s -m 30 -L "$BASE$t")"
|
||||
c="$(curl -s -o /dev/null -m 30 -L -w '%{http_code}' "$BASE$t")"
|
||||
h1="$(printf '%s' "$body" | python3 -c "
|
||||
import sys,re
|
||||
t=sys.stdin.read(); m=re.search(r'<h1[^>]*>(.*?)</h1>',t,re.S)
|
||||
print(re.sub(r'\s+',' ',re.sub(r'<[^>]+>','',m.group(1))).strip() if m else 'NO-H1')")"
|
||||
if [ "$c" = "200" ] && [ -n "$h1" ] && [ "$h1" != "NO-H1" ] && [[ "$h1" != *"$HOME_H1"* ]]; then
|
||||
ok "$t -> 200 | $h1"
|
||||
else
|
||||
bad "$t -> $c | h1='$h1'"
|
||||
fi
|
||||
done
|
||||
|
||||
echo "== 4. sitemap: ทุก URL ต้อง 200 =="
|
||||
sm="$(curl -s -m 30 "$BASE/sitemap-0.xml")"
|
||||
# ตัด <loc>…</loc> และเขียน host ใหม่ให้ตรงกับ BASE (ใช้ตรวจ nginx ในเครื่องได้)
|
||||
smurls="$(printf '%s' "$sm" \
|
||||
| grep -o '<loc>[^<]*</loc>' \
|
||||
| sed 's|<loc>||g; s|</loc>||g' \
|
||||
| sed -E "s|^https?://[^/]+|$BASE|")"
|
||||
count=0
|
||||
if [ -z "$smurls" ]; then
|
||||
bad "อ่าน sitemap-0.xml ไม่ได้"
|
||||
else
|
||||
while IFS= read -r u; do
|
||||
[ -z "$u" ] && continue
|
||||
count=$((count+1))
|
||||
c=$(code "$u")
|
||||
[ "$c" = "200" ] && pass=$((pass+1)) || bad "$u -> $c"
|
||||
done <<< "$smurls"
|
||||
ok "sitemap: ตรวจ $count URL"
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "ผลรวม: PASS=$pass FAIL=$fail (base=$BASE)"
|
||||
[ "$fail" -eq 0 ] || exit 1
|
||||
Reference in new issue
Block a user