HTTP 301 or 308
- Use when
- The move is permanent
- Google's documented guidance
- Preferred server-side method when possible; Google treats it as a signal that the target should be canonical.
Understand how Google processes JavaScript redirects, when a server redirect is safer, and how to check the final URL and rendered behavior.
A JavaScript redirect changes the browser location from script after a page loads. Google can process it during rendering, but rendering can fail, so Google recommends server-side redirects when possible and meta refresh as another option. Use JavaScript redirects only when those methods are unavailable, then test the original URL, rendered result, final status, and destination.
Four quick questions, then a straight answer.
From your answers, this is quietly costing you traffic and nobody has the hours to chase it. Scaplet finds every affected page, drafts the fixes and tracks how AI answers mention you.
A data platform shipped 46 fixes without a ticket.
This looks handled. Re-check after a redesign, a migration or a big content push; that is when it breaks.
Your site is small and you have the time. Work through the steps on this page, starting with the pages that get the most traffic.
window.location or another location property. Google processes JavaScript in a crawl, render, and index sequence. It can see a redirect during rendering, but Google warns that rendering may fail, in which case it might never see the client-side redirect.locationFor a migration or permanent URL change, a script is usually extra work: Google recommends an HTTP permanent redirect whenever technically possible. See 301 redirects for choosing permanent versus temporary behavior.
Open DevTools Network, enable Preserve log, and visit the source URL in a private window. Record the initial HTTP status, script requests, document navigations, and final address.
If the redirect only happens with JavaScript enabled, it is client-side. This is a useful diagnostic comparison, not a complete reproduction of Google's renderer.
In Search Console, use URL Inspection and view the tested page. Check whether scripts loaded, whether the redirect ran, and whether the final page is the one you intended.
Open the final URL without relying on the redirect. Confirm it returns the correct status, loads the intended content, and has a canonical that points to the preferred URL.
the location change never runs. Check blocked or failed bundles in Network, then move the redirect to the server or make the script dependency reliable.
a missing cookie, local storage value, or API response can send crawlers to the wrong URL. Google says its Web Rendering Service does not retain state across page loads; make the destination resolve without prior interactions.
keep country or language suggestions from automatically replacing a stable URL when users and crawlers should stay on that version. Provide a direct, crawlable path to each localized page.
Google may skip rendering non-200 pages. Return the right server status and redirect at the server when the content has permanently moved.
send users to the closest replacement, not a generic page. A redirect to an error-like destination can be treated as a soft 404.
A single-page app has a different problem when it handles a missing route in JavaScript but the server returns 200. Google documents that this can make error pages appear in Search. For a missing route, return a real 404, or use Google's documented SPA strategy to send the user to a server URL that returns 404 or add noindex to the client-side error view. See JavaScript SEO and HTTP status codes.
Use JavaScript redirects only when there is a concrete platform limitation. If you can configure the response at the server, a server-side redirect is clearer to browsers, crawlers, and monitoring tools.
3 questions people ask next, answered from the sources on this page.
Google can process them during rendering, but rendering can fail. Google recommends JavaScript redirects only when server-side or meta refresh redirects are unavailable.
Google's redirect table lists JavaScript location under permanent redirects, with the caveat that rendering can fail and Google might never see it. If the move is temporary, use an HTTP 302, 303, or 307 so the signal does not depend on rendering.
Use a server-side 301 or 308 for a permanent move when possible. Google recommends server-side permanent redirects and says JavaScript should be a fallback.
Run the free audit, then approve the fixes. Every change can be undone.