On this page
What this issue is
An infinite redirect loop is when a page keeps sending the browser to another page, and that page sends it back or to a third page that leads to the first. Server redirects (301 or 302) can loop, but this guide covers loops started by JavaScript, such as window.location.href = ..., location.replace(...) or a meta refresh added by a script.
- A geo or language redirect that does not check whether the visitor is already on the right version
- A login or consent check that redirects to a page which runs the same check
- A www / non-www or http / https fix in JavaScript that fights a server rule
- A redirect that depends on a cookie or localStorage value the browser blocks, so it never remembers it already ran
- An A/B testing or personalisation script that sends visitors to a variant, and the variant sends them back
- A mobile or desktop redirect script that disagrees with a responsive page
Why it costs you leads or sales
- Ad clickVisitor arrives from an ad or search result
- Landing pageScript redirects to /region and back, again and again
- Form or productNever reached
- Lead or saleNever recorded
The visitor never gets past the landing page, so every later step is lost.
Example: if a loop affects visitors with cookies blocked, those visitors never reach the form. Numbers are illustrative.
How to check if your site has it
Open the page in a private window
Use a fresh private or incognito window so no cookies or saved values hide the problem. Watch whether the page reloads repeatedly or the address bar keeps changing.
Open DevTools before loading
Press F12, go to the Network tab and tick Preserve log. Load the page and look for the same URLs repeating. A document request followed by another document request to a different URL is a sign.
Test the variations
Try with and without www, http and https, with your ad URL parameters (utm_source, gclid), with cookies blocked, on mobile, and with a VPN or browser language set to another region.
Find the script that redirects
In the Sources tab, search all files (Ctrl+Shift+F or Cmd+Option+F) for window.location, location.href, location.replace and location.assign. In the Network tab, the Initiator column shows which script triggered each navigation.
Check tag manager and plugins
Look in Google Tag Manager for custom HTML tags with redirect code, and in your A/B testing, geo or language tools for redirect rules.
How to fix it
// Runs on every page, including the page it sends people to
if (userCountry === 'DE') {
window.location.href = '/de/';
}(function () {
var target = '/de/';
var alreadyThere = window.location.pathname.indexOf(target) === 0;
var alreadyDecided = false;
try { alreadyDecided = sessionStorage.getItem('geo_redirected') === '1'; } catch (e) { alreadyDecided = true; }
if (userCountry === 'DE' && !alreadyThere && !alreadyDecided) {
try { sessionStorage.setItem('geo_redirected', '1'); } catch (e) {}
window.location.replace(target + window.location.search);
}
})();Find the source
Deactivate redirect, language, geo and A/B plugins one at a time and reload in a private window. Also check Settings > General: the WordPress Address and Site Address must match each other and use the same https and www form.
Check theme and header scripts
Look in Appearance > Theme File Editor (or your header and footer scripts plugin) for window.location code and add the safeguards shown above.
Check theme code
Go to Online Store > Themes > Edit code and search theme.liquid and your JS assets for window.location and location.replace.
Check markets and apps
If you use a country or language redirect app, review its rules and the Markets settings. Disable the app briefly to confirm it is the cause.
Use Preview mode
Open Preview, load the page and look for Custom HTML tags or Custom JavaScript variables that change location.
Add a blocking condition
Pause the tag, or add a trigger exception so it does not fire on the destination URL. Publish after testing.
Check custom code
Review Project Settings > Custom Code and each page's custom code for redirect scripts.
Check 301 rules
Under Hosting > 301 redirects, make sure no rule points back to a URL that redirects onward to the first.
Check funnel step settings
Open the funnel, then each step's settings and custom code (header and footer) for redirect scripts and path redirects.
Check domain settings
Make sure the funnel's domain and the step path are not redirected elsewhere by a rule that points back.
Check URL redirect manager
In SEO tools, open URL Redirect Manager and look for rules that point to each other.
Check Velo code
If Velo is on, search page code for wixLocation.to() calls that run on page load without a condition.
Check URL mappings
In Settings > Developer Tools > URL Mappings, look for rules that send one URL to another that redirects back.
Check code injection
Review Code Injection (header and footer) and page-level injection for location redirects.
Search the codebase
Search for location.href, location.replace, location.assign and meta refresh tags. Add a path check and a remembered decision to each.
Align server and client rules
If your server also redirects (for example to https or www), make sure the script does not undo it.
How to confirm it's fixed
- Load the page in a fresh private window and confirm it settles on one URL
- Repeat with cookies and site data blocked
- Repeat with your ad URL parameters and check they are still in the final address
- Test mobile, desktop and at least two browsers
- Test from another region or with a different browser language if you redirect by location
- In the Network tab, confirm there are no repeated document requests
- Confirm the form or checkout step loads and works
How to prevent it happening again
- Every JavaScript redirect checks where the visitor already is
- Remember the decision for the session and do not redirect when storage is blocked
- Keep one owner for each redirect rule so server, plugin and script rules do not fight
- Test redirects with a clean browser after any change to domains, https, languages or A/B tests
- Review tag manager changes in Preview mode before publishing
- Monitor your key landing pages on a schedule
How FunnelGuard handles this
Questions people ask
Why does my page keep reloading and redirecting?
A script on the page is probably sending the browser to a URL, and the page at that URL runs the same script again. Check the Network tab's Initiator column and search your code, plugins and tag manager for window.location, location.replace or location.assign.
What causes a JavaScript redirect loop?
The usual causes are a geo or language redirect with no check for the current page, a login or consent check that redirects to a page running the same check, and a redirect that relies on a cookie or storage value the browser blocks. Server rules that fight a script can also cause it.
How do I stop a JavaScript redirect loop?
Make the redirect conditional. Check that the visitor is not already on the target URL, store that the redirect happened (for example in sessionStorage), and skip the redirect if storage is unavailable.
Is a JavaScript redirect loop the same as ERR_TOO_MANY_REDIRECTS?
Not always. ERR_TOO_MANY_REDIRECTS is shown for server-side redirect chains. JavaScript loops may give no error at all, just a flashing, reloading or frozen page, so they are easier to miss.
Why does the redirect loop only happen for some visitors?
Redirects often depend on country, language, device, cookies or URL parameters. A visitor who blocks cookies, or arrives from another region or with certain parameters, can hit a loop you never see yourself.
Does a redirect loop affect ad tracking?
Yes. If the page never settles, tracking tags may fire many times or never, and click IDs and UTM parameters can be lost along the way. Keep the query string when you redirect.
Can FunnelGuard detect a redirect loop?
Yes. Its scheduled robot visits check for timeouts and redirects, and a loop that stops the journey is flagged after a second-region re-check. It may miss loops that only affect certain countries, browsers or cookie settings.
Related issues
- PRF-116Uncaught JavaScript exception on page loadFix guide
- PRF-133Page stuck on loading spinner foreverFix guide
- PRF-125Content Security Policy blocks a needed script or tagFix guide
- PRF-131localStorage/cookies unavailable (private mode) breaks the appFix guide
- PRF-117Console error on a funnel stepFix guide
- PRF-118Unhandled promise rejectionFix guide