Panduan JavaScript Redirects
What sebuah JavaScript redirect adalah, how Google's render pipeline treats ini differently dari sebuah server-side 301, when ini adalah sebuah acceptable last resort, dan cara implement dan detect one — plus where meta refresh dan History API fit.
Bahasa
1 sinyal bukti di halaman ini
- Alat aktif terkaitrobots.txt Tester
sebuah JavaScript redirect mengirim pengguna dan crawler untuk sebuah baru URL dengan client-side code (window.location.replace() atau.href). ini adalah paling sedikit reliable redirect jenis because Google hanya sees ini setelah rendering — which dapat menjadi delayed, atau fail entirely, dengan no fixed timeline either cara. Google's official order dari preference adalah server-side (301/302/307/308) → meta refresh → JavaScript, dan -nya docs say plainly: hanya gunakan JS redirects jika Anda dapat't melakukan lainnya two. Once Google successfully interprets one, target becomes sebuah canonicalization signal — tetapi itu's not sebuah proven guarantee dari identical PageRank atau peringkat outcomes untuk sebuah 301, so treat ini sebagai sebuah last resort alih-alih sebuah like-untuk-like swap. gunakan them pada constrained platforms dengan no server access, untuk SPA halaman error itu poin untuk sebuah nyata 404, dan little else. jika Anda harus gunakan one, gunakan window.location.replace() di <head>, drop source URL dari Anda sitemap, dan poin tautan internal di akhir destination. Meta refresh adalah sebuah separate HTML-tingkat redirect, dan history.pushState()/replaceState() aren't redirects di semua.
TL;DR — sebuah JavaScript redirect menggunakan code di halaman untuk kirim Anda untuk sebuah berbeda URL setelah halaman memuat. ini berfungsi untuk people, tetapi mesin pencari handle ini less reliably daripada sebuah “real” (terjemahan) “nyata” server redirect (sebuah 301). jika Anda dapat siapkan sebuah 301 instead, melakukan itu. Save JavaScript redirects untuk when Anda memiliki no lainnya option.
What sebuah JavaScript redirect adalah
sebuah JavaScript redirect perubahan navigation melalui script execution alih-alih sebuah HTTP 3xx respons. Evidence for this claim Primary standard or official documentation supporting the adjacent article claim. Scope: Protocol semantics and Search behavior are kept separate; no indexing, ranking, or migration-timing guarantee is inferred. Confidence: high · Verified: Google: JavaScript redirects Google dapat process JavaScript redirects tetapi recommends server-side redirects when mungkin. Evidence for this claim Primary standard or official documentation supporting the adjacent article claim. Scope: Protocol semantics and Search behavior are kept separate; no indexing, ranking, or migration-timing guarantee is inferred. Confidence: high · Verified: Google: Redirects and Search
ada two broad cara untuk kirim someone dari one URL untuk lainnya.
pertama adalah sebuah server-side redirect. sebelum halaman bahkan memuat, server says “that page moved — go here instead” (terjemahan) “itu halaman moved — go here instead” menggunakan sebuah kode status like 301 (permanent) atau 302 (temporary). browser dan mesin pencari both get itu message immediately.
kedua adalah sebuah JavaScript redirect. halaman memuat normally, dan lalu sebuah bit dari code runs di browser dan mengirim Anda somewhere else. Something like:
<script>
window.location.replace("https://example.com/new-page/");
</script>untuk sebuah person clicking sekitar, two feel almost yang sama. untuk sebuah mesin pencari, mereka’re very berbeda — dan itu difference adalah whole alasan ini halaman exists.
Why mesin pencari treat them differently
Google reads Anda halaman di stages. pertama ini melakukan crawl (downloads raw HTML). Later ini renders halaman — actually running JavaScript, cara sebuah browser akan. sebuah server-side 301 adalah terlihat di itu pertama langkah. sebuah JavaScript redirect isn’t terlihat until rendering langkah, which dapat come much later — atau, sometimes, not di semua.
Google says ini directly: “Only use JavaScript redirects if you can’t do server-side or meta refresh redirects.” (terjemahan) “hanya gunakan JavaScript redirects jika Anda dapat’t melakukan server-side atau meta refresh redirects.” (Google Search Central)
So sebuah JavaScript redirect isn’t buruk — ini adalah hanya less reliable. Google akan biasanya get there eventually, tetapi sebuah nyata 301 adalah faster dan more certain.
sederhana aturan
- dapat Anda set sebuah 301 (atau 302)? melakukan itu. ini adalah gold standard.
- dapat’t touch server, tetapi dapat edit HTML
<head>? sebuah 0-kedua meta refresh adalah next-best option. - Neither? lalu sebuah JavaScript redirect adalah sebuah fine last resort.
sebuah couple dari things people get wrong:
- sebuah meta refresh adalah not sebuah JavaScript redirect. ini adalah sebuah
<meta>tag di Anda HTML, dan Google handles ini earlier dan more reliably daripada JS. history.pushState()adalah not sebuah redirect. ini hanya perubahan what’s di address bar — ini doesn’t kirim anyone anywhere, dan mesin pencari don’t ikuti ini.
ingin render-pipeline timing, implementation detail, dan cara temukan JS redirects di sebuah crawl? Switch untuk Advanced tab.
TL;DR — sebuah JavaScript redirect adalah sebuah client-side redirect (
window.location.replace(),.href,.assign()) itu Google hanya processes setelah rendering — phase three dari crawl → render → indeks. sebuah server-side 301 adalah seen di crawl time; sebuah JS redirect waits pada render queue, dan Google gives no fixed timeline untuk itu wait — ini dapat menjadi quick atau ini dapat take sebuah panjang while, dan rendering dapat fail outright. Google’s documented preference order adalah server-side → meta refresh → JavaScript, dan docs say untuk gunakan JS redirects hanya when Anda dapat’t melakukan lainnya two. Once Google successfully interprets one, target becomes sebuah permanent canonicalization signal — bahkan Google digunakan them pada mereka own blog when nothing else worked — tetapi itu’s not documented proof dari identical PageRank atau peringkat outcomes untuk sebuah 301, so mereka’re sebuah last resort, not sebuah spam signal. legitimate menggunakan adalah constrained platforms dengan no server config dan SPA halaman error itu poin di sebuah nyata 404. Implement denganwindow.location.replace()di<head>, drop source dari Anda sitemap, repoint tautan internal, dan confirm Googlebot dapat fetch JS. Meta refresh adalah HTML-tingkat (0s = permanent, apa pun delay = temporary), danhistory.pushState()/replaceState()aren’t redirects di semua.
What counts sebagai sebuah JavaScript redirect
Script navigation depends pada rendering dan execution, so ini adalah not protocol-equivalent untuk sebuah HTTP redirect. Evidence for this claim Primary standard or official documentation supporting the adjacent article claim. Scope: Protocol semantics and Search behavior are kept separate; no indexing, ranking, or migration-timing guarantee is inferred. Confidence: high · Verified: Google: JavaScript redirects Processing adalah mungkin, not sebuah exact-timing atau pengindeksan guarantee. Evidence for this claim Primary standard or official documentation supporting the adjacent article claim. Scope: Protocol semantics and Search behavior are kept separate; no indexing, ranking, or migration-timing guarantee is inferred. Confidence: high · Verified: Google: Redirects and Search
sebuah JavaScript redirect navigates browser untuk sebuah baru URL dengan client-side code. umum metode, dan how mereka differ:
window.location.replace("url")— navigates dan menghapus original URL dari session history. ini adalah one untuk gunakan: back button skips redirect source alih-alih bouncing pengguna straight back.window.location.href = "url"— navigates tetapi mempertahankan original di history, so back button mengembalikan untuk redirecting halaman (dan dapat buat loop).document.location.hrefdanwindow.location.assign("url")behave sama cara.history.pushState()/history.replaceState()— not redirects. mereka rewrite address bar without apa pun navigation atau HTTP signal, so crawler don’t treat them sebagai redirects. SPAs gunakan them untuk di-app URL perubahan; mereka perlu nyata<a href>tautan (atau actual navigations) untuk menjadi dapat di-crawl.
dividing line itu penting: .replace(), .href, dan .assign() semua trigger
sebuah nyata document navigation ( difference antara them adalah hanya what happens untuk
session history), while pushState()/replaceState() tidak pernah navigate di semua —
mereka touch history state dan address bar dan nothing else. None dari four adalah
sebuah HTTP 301; “redirect” (terjemahan) “redirect” here adalah shorthand untuk client-side navigation, not sebuah status
code.
Meta refresh (<meta http-equiv="refresh" content="0;url=...">) adalah sering
lumped di dengan JS redirects, tetapi ini adalah sebuah HTML directive parsed sebelum JavaScript
runs — sebuah separate, more reliable category, covered below.
How Google processes sebuah JavaScript redirect
ini adalah crux. Google’s pipeline runs di stages, dan sebuah JS redirect dan sebuah server-side redirect get caught di berbeda ones:
- crawl — Googlebot fetches URL dan reads raw HTML. sebuah server-side 301/302/307/308 adalah seen right here.
- Render queue — halaman itu kembalikan
200wait untuk menjadi rendered. Google’s docs note halaman “may stay on this queue for a few seconds, but it can take longer than that.” (terjemahan) “dapat stay pada ini queue untuk sebuah few seconds, tetapi ini dapat take longer daripada itu.” Google doesn’t publish sebuah fixed service-tingkat timeline beyond itu, so treat wait sebagai unpredictable — ini dapat menjadi quick, atau ini dapat drag — rather daripada assuming apa pun spesifik angka dari days atau weeks. - Render + indeks — headless Chromium runs JavaScript. ini adalah pertama moment sebuah JS redirect exists sebagai far sebagai Google adalah concerned.
yang sama idea I membuat pada crawling dan di JavaScript SEO applies here: rendering adalah sebuah separate langkah dari fetching, dan anything itu depends pada ini inherits itu delay dan itu risk.
dan risk adalah nyata. Google: “While Google attempts to render every URL Googlebot crawled, rendering may fail for various reasons. This means that if you set a JavaScript redirect, Google might never see it if rendering of the content failed.” (terjemahan) “While Google attempts untuk render setiap URL Googlebot di-crawl, rendering dapat fail untuk various alasan. ini berarti itu jika Anda set sebuah JavaScript redirect, Google mungkin tidak pernah see ini jika rendering dari konten failed.” (Google Search Central) selama window sebelum redirect adalah processed — dan forever, jika rendering fails — Google dapat pertahankan empty source halaman di -nya indeks.
Google’s official preference order
redirects documentation lays out sebuah hierarchy dari sebagian besar untuk least reliable:
- server-side redirects — 301/308 (permanent), 302/307 (temporary). Best untuk everything: seen di crawl time, unambiguous.
- Meta refresh — HTML-tingkat. sebuah 0-kedua meta refresh adalah treated sebagai sebuah permanent redirect (like sebuah 301); apa pun delayed meta refresh adalah treated sebagai temporary.
- JavaScript redirects — last resort.
Google’s kata: “Only use JavaScript redirects if you can’t do server-side or meta refresh redirects.” (terjemahan) “hanya gunakan JavaScript redirects jika Anda dapat’t melakukan server-side atau meta refresh redirects.” Permanent redirects pass canonical signal untuk target; temporary ones pertahankan original di hasil. (How itu interacts dengan canonical selection adalah di atas pada Canonicalization.)
melakukan tautan equity pass melalui?
Google’s own redirects documentation lists JavaScript location navigation among -nya permanent redirection metode, dan says target becomes canonicalization signal once Google memiliki interpreted ini — so flat “JS redirects don’t pass PageRank” (terjemahan) “JS redirects don’t pass PageRank” claim adalah salah. What documentation doesn’t establish adalah itu outcome adalah identical, immediate, atau sebagai reliable sebagai sebuah server-side 301 — ini describes canonical signal, not sebuah guarantee dari matching PageRank flow, peringkat, atau timing. honest framing: sebuah 301 passes signal di crawl time dengan near-certainty; sebuah JS redirect passes ini hanya jika dan when rendering succeeds, dan Google doesn’t promise hasil akan match sebuah 301’s outcome one-untuk-one. itu gap — not lost equity — adalah nyata cost dari choosing JavaScript.
ini adalah juga why JS redirects aren’t sebuah penalty trigger pada mereka own. mereka hanya become sebuah spam masalah when mereka’re digunakan untuk cloaking — showing crawler one halaman dan redirecting pengguna untuk something berbeda, atau sending mobile pengguna untuk sebuah unrelated domain. Google’s sneaky redirects policy adalah tentang itu intent, not technique.
When sebuah JavaScript redirect adalah right alat
ada legitimate cases:
- Constrained platforms. beberapa shared hosting, CDN, atau CMS setups give Anda no access untuk server-side redirect aturan. sebuah JS redirect adalah sebuah valid fallback — dan notably, Google digunakan JS redirects pada mereka own Webmaster blog because, sebagai Gary Illyes put ini, “that was the only thing we could use for 1:1 redirects, and it works on Google” (terjemahan) “itu adalah satu-satunya thing kami dapat gunakan untuk 1:1 redirects, dan ini berfungsi pada Google” (OnCrawl).
- SPA error handling. Google explicitly endorses ini: “Use a JavaScript
redirect to a URL for which the server responds with a
404HTTP status code.” (terjemahan) “gunakan JavaScript redirect untuk sebuah URL untuk which server responds dengan sebuah undefined HTTP kode status.” (Google Search Central) sebuah single-halaman app itu resolves sebuah buruk route dapat redirect untuk sebuah nyata 404 endpoint so Google processes error correctly alih-alih pengindeksan sebuah soft 404.
untuk permanent URL migrations, ini adalah not alat — gunakan 301. I membuat yang sama poin di situs migrations: JavaScript redirects adalah sebuah last resort, dan Google dapat tidak pernah see them.
Static situs generators: Hugo aliases trap
sebuah umum surprise: Hugo’s aliases: frontmatter memiliki historically generated
meta refresh HTML halaman, not server-side 301s — dan lainnya static generators
memiliki done similar things oleh default. Generator defaults perubahan antara versi,
so periksa Anda saat ini deployed versi’s actual output alih-alih assuming; jika
aliases: isn’t giving Anda 301s, Anda perlu platform-tingkat redirect aturan (Netlify
_redirects, Cloudflare Workers, Vercel vercel.json) plus (pada Hugo)
disableAliases: true. I cover ini di detail di
Hugo SEO.
Implementation best practices
jika sebuah JavaScript redirect adalah genuinely Anda hanya option:
- gunakan
window.location.replace(), not.href. sebagai mesin pencari Journal puts ini, JS redirects “typically usewindow.location.replace()function rather thanwindow.location.hrefto avoid UX redirect loops” (terjemahan) “typically gunakan undefined function alih-alih undefined untuk hindari UX redirect loops” (SEJ). - Put ini di
<head>, not<body>. browser parse HTML sequentially dan run scripts sebagai mereka hit them, so “position JavaScript redirects in the<head>tag rather than<body>to minimize delay” (terjemahan) “position JavaScript redirects di undefined tag alih-alih undefined untuk minimize delay” (OnCrawl). - Redirect untuk akhir destination di one hop. sebuah JS redirect untuk sebuah halaman itu itself 301s elsewhere membuat sebuah chain; chains waste anggaran crawling dan dapat surface di GSC sebagai sebuah redirect error.
- hapus source URL dari Anda sitemap XML. Sitemaps seharusnya list canonical, dapat diindeks URLs — not redirecting ones.
- Repoint tautan internal di destination, so mereka don’t route melalui redirect di semua.
- pastikan Googlebot dapat fetch JS. jika redirect lives di sebuah external
script blocked oleh
robots.txt, Google dapat’t render ini dan won’t see redirect.
cara detect JavaScript redirects
mereka don’t announce themselves like sebuah 301 di sebuah header, so Anda memiliki untuk render:
- sebuah crawler dengan JS rendering pada. OnCrawl recommends crawling dengan
“JavaScript rendering enabled (5-second timeout minimum)” (terjemahan) “JavaScript rendering enabled (5-kedua timeout minimum)”; Screaming Frog dan
Ahrefs situs Audit dapat both render. Without rendering, sebuah JS-redirecting halaman hanya
looks like sebuah normal
200. - Chrome DevTools. Network tab (dengan “Preserve log” (terjemahan) “pertahankan log”) menampilkan client-side navigation; Redirect Path extension flags ini too.
- di Search Console, sebuah successfully processed JS redirect menampilkan up di bawah halaman dengan redirect — yang sama status sebagai apa pun redirected URL, which adalah normal untuk non-canonical sources. itu label isn’t guaranteed pada apa pun given periksa, though: ini reflects whatever Google fetched, rendered, interpreted, dan canonicalized di sampled moment, so sebuah URL dapat tampilkan sebuah berbeda status (atau no redirect status yet) antara memeriksa without itu menjadi sebuah error pada Anda end.
What I’d actually melakukan
server-side pertama, setiap time. Meta refresh (0-kedua) when Anda dapat edit HTML tetapi
not server config. JavaScript hanya when both adalah off table — dan lalu dengan
window.location.replace() di <head>, sebuah clean sitemap, dan sebuah periksa bahwa
redirect actually renders untuk Googlebot. untuk anything permanent atau tinggi-nilai,
extra reliability dari sebuah 301 adalah worth almost apa pun effort untuk obtain.
AI summary
sebuah condensed take pada Advanced versi:
- sebuah JavaScript redirect adalah client-side (
window.location.replace(),.href,.assign()). ini adalah hanya processed setelah rendering — phase three dari crawl → render → indeks — whereas sebuah server-side 301 adalah seen di crawl time. - ** render queue adalah risk:** sebuah halaman “may stay on this queue for a few seconds, but it can take longer,” (terjemahan) “dapat stay pada ini queue untuk sebuah few seconds, tetapi ini dapat take longer,” dengan no fixed service-tingkat timeline, dan rendering dapat fail entirely, di which case Google dapat tidak pernah see redirect dan mempertahankan source halaman terindeks.
- Google’s preference order: server-side (301/302/307/308) → meta refresh → JavaScript. Docs: “Only use JavaScript redirects if you can’t do server-side or meta refresh redirects.” (terjemahan) “hanya gunakan JavaScript redirects jika Anda dapat’t melakukan server-side atau meta refresh redirects.”
- ** target becomes sebuah canonicalization signal** once Google interprets sebuah JS redirect — so “JS redirects don’t pass PageRank” (terjemahan) “JS redirects don’t pass PageRank” myth adalah salah — tetapi Google doesn’t document itu outcome matches sebuah server-side redirect’s PageRank flow, peringkat, atau timing exactly. JS redirects aren’t sebuah penalty trigger unless digunakan untuk cloaking (sneaky redirects).
- Legitimate menggunakan: constrained platforms (Google itself digunakan them pada mereka blog), dan SPA halaman error itu redirect untuk sebuah nyata 404 (Google-endorsed).
- Meta refresh ≠ JS redirect: ini adalah HTML-tingkat; 0s = permanent, apa pun delay =
temporary.
history.pushState()/replaceState()aren’t redirects — no HTTP signal, crawler don’t ikuti them. - Hugo
aliases:adalah meta refresh, not 301s — sebuah umum trap pada static generators. - Implementation:
window.location.replace()di<head>, single hop untuk destination, hapus source dari sitemap, repoint tautan internal, ensure Googlebot dapat fetch JS. - Detection: crawl dengan JS rendering pada, Chrome DevTools / Redirect Path, “Page with redirect” (terjemahan) “halaman dengan redirect” di GSC.
Official documentation
Primary-source guidance pada redirects dan JavaScript.
- Redirects dan Google Search — preference hierarchy (server-side → meta refresh → JavaScript), permanent vs. temporary handling, dan meta refresh delay aturan.
- JavaScript SEO Basics — render pipeline dan endorsed SPA-404 redirect gunakan case.
- Fix search-related JavaScript masalah — soft 404s, rendering, dan debugging JS itu Google dapat’t process.
- Sneaky redirects (spam policies) — when sebuah redirect crosses ke cloaking dan becomes sebuah policy violation.
Bing / Microsoft
- Bing Webmaster Help — entry poin untuk Bing’s saat ini guidance. (di time dari writing, Bing memiliki no dedicated redirects help halaman di sebuah stable URL; Bingbot renders JavaScript less reliably daripada Googlebot, which membuat JS-hanya redirects riskier untuk Bing pengindeksan.)
Quotes dari source
pada—record statements dari Google dan people who berfungsi pada Search. setiap Google-docs tautan adalah sebuah deep tautan itu jumps untuk quoted passage.
Google — preference order dan rendering risk
- “Only use JavaScript redirects if you can’t do server-side or meta refresh redirects.” (terjemahan) “hanya gunakan JavaScript redirects jika Anda dapat’t melakukan server-side atau meta refresh redirects.” — Google Search Central docs. Jump untuk quote
- “While Google attempts to render every URL Googlebot crawled, rendering may fail for various reasons. This means that if you set a JavaScript redirect, Google might never see it if rendering of the content failed.” (terjemahan) “While Google attempts untuk render setiap URL Googlebot di-crawl, rendering dapat fail untuk various alasan. ini berarti itu jika Anda set sebuah JavaScript redirect, Google mungkin tidak pernah see ini jika rendering dari konten failed.” — Google Search Central docs. Jump untuk quote
Google — endorsed SPA gunakan case
- “Use a JavaScript redirect to a URL for which the server responds with a
404HTTP status code (for example/not-found).” (terjemahan) “gunakan JavaScript redirect untuk sebuah URL untuk which server responds dengan sebuah undefined HTTP kode status (misalnya undefined).” — Google Search Central docs. Jump untuk quote
Gary Illyes, Google
- pada JS redirects umumnya: “Js redirects are probably not a good idea though.” (terjemahan) “Js redirects adalah probably not sebuah baik idea though.” (July 8, 2020)
- pada Google menggunakan them anyway when nothing else worked: “We used JS redirects on webmasters.googleblog.com because that was the only thing we could use for 1:1 redirects, and it works on Google.” (terjemahan) “kami digunakan JS redirects pada webmasters.googleblog.com because itu adalah satu-satunya thing kami dapat gunakan untuk 1:1 redirects, dan ini berfungsi pada Google.” Coverage
mesin pencari Journal — implementation dan tautan equity
- “JavaScript redirects typically use
window.location.replace()function rather thanwindow.location.hrefto avoid UX redirect loops.” (terjemahan) “JavaScript redirects typically gunakan undefined function alih-alih undefined untuk hindari UX redirect loops.” Read - “JavaScript redirects are not SEO-friendly and should be avoided when alternatives exist… Only implement JavaScript redirects when server-side alternatives are genuinely unavailable.” (terjemahan) “JavaScript redirects adalah not SEO-friendly dan seharusnya menjadi avoided when alternatives exist… hanya implement JavaScript redirects when server-side alternatives adalah genuinely unavailable.” Read
Redirect jenis — cheat sheet
When Google sees ini, dan how ini adalah treated
| metode | When Google sees ini | Treated sebagai | Reliability |
|---|---|---|---|
server-side 301 / 308 | crawl time | Permanent | Highest |
server-side 302 / 307 | crawl time | Temporary | Highest |
Meta refresh, 0 seconds | HTML parse time | Permanent | tinggi |
Meta refresh, delayed (>0s) | HTML parse time | Temporary | tinggi |
| JavaScript redirect | setelah rendering | mengikuti navigation | Lowest |
history.pushState() / replaceState() | — | Not sebuah redirect | n/sebuah |
JavaScript redirect metode
| Code | History perilaku | gunakan ini? |
|---|---|---|
window.location.replace("url") | menghapus source dari history | Yes — recommended |
window.location.href = "url" | mempertahankan source (back-button loop) | hindari untuk redirects |
window.location.assign("url") | sama sebagai .href | hindari untuk redirects |
document.location.href = "url" | Alias untuk .href | hindari untuk redirects |
Fast facts
- Google’s order: server-side → meta refresh → JavaScript. gunakan JS hanya when pertama two adalah impossible.
- Once interpreted, sebuah JS redirect’s target adalah sebuah canonicalization signal — “JS redirects don’t pass PageRank” (terjemahan) “JS redirects don’t pass PageRank” myth adalah salah. Google doesn’t document itu outcome sebagai identical untuk sebuah 301’s, so nyata risk adalah delay / render failure, not sebuah documented PageRank penalty.
- JS redirects adalah not sebuah penalty unless digunakan untuk cloaking.
- Hugo
aliases:= meta refresh, not 301. - sebuah processed JS redirect appears sebagai “Page with redirect” (terjemahan) “halaman dengan redirect” di GSC.
seharusnya I gunakan JavaScript redirect? — decision checklist
Walk ini top untuk bottom; stop di pertama “yes.” (terjemahan) “yes.”
- dapat I set sebuah server-side
301/302/307/308? → melakukan itu. Stop here. - dapat I edit HTML
<head>tetapi not server config? → gunakan 0-kedua meta refresh untuk permanent moves. Stop here. - Neither adalah mungkin (locked-down platform), atau ini adalah sebuah SPA halaman error itu seharusnya hit sebuah nyata 404? → sebuah JavaScript redirect adalah acceptable. Continue.
jika Anda’re menggunakan sebuah JavaScript redirect
- gunakan
window.location.replace()(not.href/.assign()). - Place script di
<head>, sebagai early sebagai mungkin. - Redirect straight untuk akhir destination — no chain melalui lainnya redirect.
- hapus source URL dari Anda sitemap XML.
- Repoint tautan internal untuk destination.
- Confirm redirect’s JS adalah not blocked di
robots.txtso Googlebot dapat render ini. - Anda adalah not showing crawler one halaman dan redirecting pengguna elsewhere (cloaking).
- Verify oleh crawling dengan JS rendering pada dan memeriksa “Page with redirect” (terjemahan) “halaman dengan redirect” di GSC.
recommended JavaScript redirect
Put ini di <head> so ini executes sebagai early sebagai mungkin di parse order:
<head>
<script>
window.location.replace("https://example.com/new-page/");
</script>
</head>replace() adalah key choice — ini drops redirecting URL dari session history,
so back button doesn’t bounce pengguna straight back ke redirect.
0-kedua meta refresh (next-best when Anda dapat’t melakukan server-side)
Not JavaScript, tetapi right fallback when Anda dapat edit HTML dan not server config. sebuah 0-kedua delay adalah treated oleh Google sebagai sebuah permanent redirect:
<head>
<meta http-equiv="refresh" content="0; url=https://example.com/new-page/">
</head>What NOT untuk gunakan sebagai sebuah redirect
history.pushState() rewrites address bar tetapi performs no navigation dan
mengirim no HTTP signal — crawler won’t ikuti ini:
// NOT a redirect — only changes the URL bar, no navigation happens
history.pushState({}, "", "/new-page/");jika Anda perlu sebuah SPA route perubahan untuk menjadi dapat di-crawl, give ini sebuah nyata <a href> tautan atau
sebuah genuine navigation, not hanya sebuah History API panggil.
SPA halaman error → nyata 404 (Google-endorsed pattern)
When sebuah single-halaman app resolves sebuah unknown route, kirim ini untuk sebuah endpoint itu
mengembalikan sebuah actual 404 so Google processes error alih-alih sebuah soft 404:
// On an unresolved route in your SPA:
window.location.href = "/not-found"; // /not-found must return HTTP 404 alat untuk finding dan memeriksa JavaScript redirects
- Screaming Frog SEO Spider — enable JavaScript rendering (dengan sebuah sufficient
rendering timeout) so JS-redirecting halaman don’t hanya look like plain
200s. - Ahrefs situs Audit — renders halaman dan surfaces redirects, chains, dan redirected tautan internal.
- Chrome DevTools — Network tab — turn pada “Preserve log” (terjemahan) “pertahankan log” dan watch client-side navigation fire.
- Redirect Path (Chrome extension) — flags client-side redirects alongside server-side ones di sebuah quick popup.
- Google Search Console — pemeriksaan URL — see how sebuah single URL adalah di-crawl dan rendered, dan whether Google landed pada “Page with redirect.” (terjemahan) “halaman dengan redirect.”
- GSC — halaman pengindeksan report — “Page with redirect” (terjemahan) “halaman dengan redirect” lists redirected URLs; “Redirect error” (terjemahan) “Redirect error” surfaces chains dan loops.
Mistakes untuk hindari dengan JavaScript redirects
- menggunakan
window.location.href(atau.assign()) alih-alih.replace()..hrefmempertahankan redirecting halaman di session history, so back button bounces pengguna straight back ke redirect — sebuah loop. melakukan instead: gunakanwindow.location.replace(), which drops source dari history. - Reaching untuk sebuah JS redirect pada sebuah permanent, tinggi-nilai migration when sebuah 301 adalah available. JS redirects adalah hanya processed setelah rendering, which dapat menjadi delayed atau fail outright — wrong risk untuk take pada sebuah halaman itu penting. melakukan instead: gunakan server-side 301; save JavaScript untuk constrained platforms dan SPA halaman error.
- Chaining JS redirect ke lainnya redirect alih-alih landing pada akhir destination di one hop. Chains waste anggaran crawling dan dapat surface sebagai sebuah redirect error di GSC. melakukan instead: poin JS redirect straight di destination URL.
- Leaving source URL di sitemap XML. Sitemaps seharusnya list canonical, dapat diindeks URLs, not redirecting ones. melakukan instead: hapus source dari sitemap once redirect adalah live.
- Letting
robots.txtblock script itu fires redirect. jika Googlebot dapat’t fetch JS, ini dapat’t render redirect, dan source halaman dapat sit terindeks indefinitely. melakukan instead: confirm script adalah dapat di-crawl — robots.txt tester memeriksa exactly ini. - Assuming Hugo’s
aliases:frontmatter gives Anda sebuah 301. ini memiliki historically generated sebuah meta refresh HTML halaman, not sebuah server-side redirect — verify Anda deployed versi’s actual output alih-alih assuming. melakukan instead: gunakan platform-tingkat redirect aturan (Netlify_redirects, Cloudflare Workers, Vercelvercel.json) plusdisableAliases: true, sebagai covered di Hugo SEO. - Treating
history.pushState()/replaceState()sebagai sebuah redirect. mereka hanya rewrite address bar — no navigation, no HTTP signal, dan crawler don’t ikuti them. melakukan instead: gunakan nyata<a href>tautan atau sebuah actual navigation untuk anything itu perlu untuk menjadi dapat di-crawl. - Showing crawler one halaman dan sending pengguna somewhere else (cloaking). ini adalah what turns sebuah legitimate JS redirect ke sebuah sneaky redirects policy violation — ini adalah tentang intent, not technique. melakukan instead: kirim everyone, bot disertakan, untuk yang sama destination.
umum issues dengan JavaScript redirects
source URL stays terindeks panjang setelah redirect went live
- mungkin cause: halaman adalah masih sitting di Google’s render queue, atau rendering failed outright.
- Fix + periksa: run sebuah Live Test di Google Search Console’s URL
Inspection alat pada source URL. jika ini hasn’t rendered yet, wait — Google
gives no fixed timeline untuk render queue, so recheck periodically rather
daripada assuming sebuah spesifik window. jika rendering mempertahankan failing, confirm
redirect script isn’t blocked (see
robots.txtissue below).
back button mengembalikan straight untuk redirecting halaman
- mungkin cause: redirect menggunakan
window.location.hrefatau.assign()alih-alih.replace(), so source URL stays di session history. - Fix + periksa: switch script untuk
window.location.replace(). Confirm oleh landing pada destination dan pressing back — ini seharusnya skip redirect source entirely.
GSC menampilkan “Crawled – currently not indexed” (terjemahan) “di-crawl – currently not terindeks” alih-alih “Page with redirect” (terjemahan) “halaman dengan redirect”
- mungkin cause: Google hasn’t rendered halaman yet, atau rendering adalah failing untuk itu URL.
- Fix + periksa: crawl URL dengan sebuah JS-rendering crawler (Screaming Frog atau
Ahrefs situs Audit, rendering enabled) untuk confirm redirect actually fires
client-side. juga periksa bahwa redirect script isn’t blocked di
robots.txt— robots.txt tester confirms whether Googlebot dapat fetch ini.
sebuah unresolved SPA route menampilkan up sebagai sebuah soft 404 di GSC
- mungkin cause: route redirects somewhere, tetapi destination doesn’t
actually kembalikan sebuah HTTP
404status. - Fix + periksa: poin redirect di sebuah endpoint itu genuinely responds
dengan
404(Google’s endorsed pattern), lalu re-run pemeriksaan URL untuk see status perubahan dari soft 404 untuk sebuah clean 404.
sebuah JS-redirecting halaman masih looks like sebuah plain 200 di sebuah crawl report
- mungkin cause: crawler ran without JavaScript rendering enabled, so ini hanya saw initial HTML respons, not client-side navigation.
- Fix + periksa: re-crawl dengan JS rendering turned pada (sebuah 5-kedua timeout minimum adalah sebuah reasonable starting poin) dan confirm redirect now menampilkan up.
Proving redirect actually took effect
| Test untuk run | Expected hasil | Failure interpretation | Monitoring window | Rollback trigger |
|---|---|---|---|---|
| robots.txt tester pada redirect script’s URL | Script adalah Allowed untuk Googlebot | Disallowed — Google dapat’t fetch script, so ini dapat tidak pernah render redirect | Immediate | Fix atau hapus blocking robots.txt aturan sebelum relying pada redirect |
| crawl source URL dengan JS rendering enabled (Screaming Frog / Ahrefs situs Audit) | crawler reports sebuah client-side navigation untuk intended destination | halaman masih reports sebuah plain 200 dengan no navigation — rendering isn’t firing | Immediate (single crawl) | jika ini masih doesn’t fire setelah fixing robots.txt, gunakan 0-kedua meta refresh atau server-side redirect instead |
| GSC pemeriksaan URL — Live Test pada source URL | Rendered hasil menampilkan redirect executing untuk destination | rendering fails, atau rendered HTML menampilkan no navigation | Immediate untuk live test itself | jika Live Test repeatedly fails untuk render, treat ini platform sebagai unable untuk mendukung sebuah JS redirect — get server access atau gunakan meta refresh |
| GSC — halaman pengindeksan report untuk source URL | Source URL adalah listed di bawah “Page with redirect” (terjemahan) “halaman dengan redirect” | masih menampilkan sebagai terindeks, “Crawled – currently not indexed,” (terjemahan) “di-crawl – currently not terindeks,” atau duplicate konten | 2–4 weeks (pengindeksan status updates pada Google’s own schedule) | jika masih not classified sebagai sebuah redirect setelah 4+ weeks, revisit render-blocking memeriksa above |
| Manual back-button periksa di sebuah browser setelah landing pada destination | Back button skips source halaman entirely | Back button mengembalikan untuk source halaman | Immediate | Switch script dari .href/.assign() untuk window.location.replace() |
Test yourself: JavaScript Redirects
Five quick pertanyaan pada how JavaScript redirects berfungsi dan when untuk gunakan them. Pick sebuah jawaban untuk setiap, lalu periksa.
Resources worth Anda time
My related writing
- JavaScript SEO Issues & Best Practices — rendering side, which adalah why JS redirects carry mereka timing risk.
- Beginner’s Guide untuk SEO teknis — where redirects dan rendering fit di bigger picture.
My speaking
- How Search berfungsi (SlideShare) — my walkthrough dari crawling, rendering, pengindeksan, dan peringkat — pipeline itu membuat sebuah JS redirect sebuah phase-three event. (My standing disclaimer applies: “This is my understanding of systems… not going to be 100% complete or accurate.” (terjemahan) “ini adalah my understanding dari sistem… not going untuk menjadi 100% complete atau accurate.”)
dari sekitar industry
- Redirects dan Google Search (Google Search Central) — official preference hierarchy dan permanent-vs-temporary handling.
- Sneaky redirects (Google Search Central) — spam-policy line itu separates sebuah legitimate redirect dari cloaking.
- JavaScript Redirects & SEO: When & cara gunakan Them (mesin pencari Journal) — practical implementation guidance dan
replace()vs.hrefdistinction. - adalah JavaScript Redirects SEO-Friendly? (mesin pencari Journal) — “avoid when alternatives exist” (terjemahan) “hindari when alternatives exist” summary.
- JavaScript Redirects dan SEO: Ultimate Guide (OnCrawl) — head-placement guidance, detection tooling, dan full Gary Illyes quote.
- adalah JavaScript Redirects buruk untuk SEO? (Conductor) — sebuah concise FAQ-style jawaban untuk informational kueri.
- sebuah Guide untuk Redirect jenis (Lumar) — broader redirect taxonomy dengan JS redirects di context.
Log perubahan
Diperbarui 18 Jul 2026.
Ringkasan editorial dan detail perubahan yang tercatat.Detail perubahan
-
Catatan perubahan terperinci saat ini tersedia dalam bahasa Inggris.
-
Catatan perubahan terperinci saat ini tersedia dalam bahasa Inggris.
-
Catatan perubahan terperinci saat ini tersedia dalam bahasa Inggris.
-
Catatan perubahan terperinci saat ini tersedia dalam bahasa Inggris.
Perbandingan lengkap tidak tersedia — tidak ada cuplikan sebelumnya yang diarsipkan untuk revisi ini.