Yönlendirme zincirlerini tek komutla bulmak

Site taşımalarından birkaç yıl sonra neredeyse her sitede yönlendirme zincirleri birikiyor. A → B → C → D gibi. Her adım biraz zaman kaybettiriyor. Tarayıcılar belli bir sayıdan sonra zinciri takip etmeyi bırakıyor.

zincir.sh
#!/usr/bin/env bash
# kullanım: ./zincir.sh urller.txt
while read -r url; do
  [ -z "$url" ] && continue
  out=$(curl -s -o /dev/null -L --max-redirs 10 --max-time 20 \
        -w '%{num_redirects} %{http_code} %{url_effective}' "$url")
  read -r hops code final <<< "$out"
  if [ "$hops" -gt 1 ]; then
    printf 'ZİNCİR (%s adım) %s → %s [%s]\n' "$hops" "$url" "$final" "$code"
  elif [ "$code" -ge 400 ] || [ "$code" = "000" ]; then
    printf 'HATA [%s] %s\n' "$code" "$url"
  fi
done < "$1"

Adımları tek tek görmek

Bir zincirin hangi adımlardan geçtiğini görmek için:

curl -sIL https://ornek.com/eski-adres | grep -iE '^(HTTP|location)'

Düzeltme kuralı

Zincirdeki her eski adresi doğrudan son hedefe yönlendir:

ÖnceSonra
/a → /b → /c/a → /c ve /b → /c

Sitenin kendi iç bağlantılarını da son adrese güncellemeyi unutma. En iyi yönlendirme, hiç ihtiyaç duyulmayan yönlendirmedir.

Comments / questions

There's no comment section here. If you have a question or want to add something, message me on Telegram or send an email to [email protected]. Thanks!

Related pages