Magento admin static files and 127.0.0.1

If the admin is on localhost and static files load from 127.0.0.1, set both base URLs to the host you actually type and flush the config cache.

Last updated: October 27, 2026

localhost and 127.0.0.1 are the same machine and different origins. Magento writes static file URLs from the base URL. If you open the admin on one host while the base URL uses the other, CSS, JS, and requirejs 404 or get blocked, and the admin looks unstyled. Pick one host and store that host in the base URL.

Paste each static file URL into the URL Parser and compare the host, scheme, and port. The host that does not match the address bar is the one stored in the base URL.

Content-Security-Policy messages in the same console are a second problem. Fix the host first. A CSP report does not mean the static file was the wrong host.

What you see

  • The address bar is http://localhost/.../admin and the network panel requests http://127.0.0.1/static/adminhtml/..., or the reverse.
  • Those static requests 404, or the console says a cross-origin stylesheet was blocked.
  • The storefront can look fine if you always open it on the host that matches its base URL.
Illustration of a browser on http://localhost/admin whose network panel requests styles.css and require.js from 127.0.0.1.
Illustration. The address bar and the stylesheet host do not match.

Why

Browsers compare scheme, host, and port. The same-origin policy treats http://localhost and http://127.0.0.1 as different sites. Cookies set for one are not sent to the other. Magento’s admin form key and session live in that cookie, so a mixed host also produces “invalid form key” after login redirects.

Static URLs are not guessed from the address bar. They come from web/unsecure/base_url and web/secure/base_url.

Fix

  1. Choose the host you will type. http://localhost/ is fine for a single local site. A named host such as http://shop.test/ is better once you have two projects.
  1. Read the stored URL. From the Magento root:
php bin/magento config:show web/unsecure/base_url
php bin/magento config:show web/secure/base_url
  1. Set both to the same origin, including the trailing slash:
php bin/magento config:set web/unsecure/base_url http://localhost/
php bin/magento config:set web/secure/base_url http://localhost/

Use https://shop.test/ when TLS is actually terminating. Do not set the secure URL to https://127.0.0.1/ while you browse http://localhost/.

  1. Clear the caches that stored the old URL:
php bin/magento cache:flush

In developer mode, static files are generated on request. In production mode, redeploy:

php bin/magento setup:static-content:deploy -f en_US

Add your real locale codes. -f is required in developer mode; omit the force flag in production if the command accepts the run without it.

  1. Open the admin only at the host you saved. Hard-reload once so the browser drops the old HTML.

In the browser network panel, open a failed stylesheet and read the request host. It must match the host in the address bar, including localhost versus 127.0.0.1 and http versus https. A file that returns 200 from the other host is still the wrong origin.

Check the result

View source on the admin login page. Every static/adminhtml URL starts with the same scheme and host as the address bar. The network panel shows 200 for css/styles.css and requirejs/require.js. The login form posts back to that same host.

If that does not work

  • core_config_data has a store-scope row that still points at the other host. config:show prints the merged value; check the table if a website scope overrides default.
  • app/etc/env.php does not cause this by itself. A CDN or pub/static rewrite might. The network panel is the authority.
  • Windows resolves localhost to ::1 first. If only IPv4 is listening, browse 127.0.0.1 and set the base URL to http://127.0.0.1/, or make Apache listen on IPv6. Do not mix them.
  • Cookie domain is .localhost or a parent you do not use. Set web/cookie/cookie_domain empty for a single local host.
  • Files 404 even when the host matches. That is a static deploy or permission problem, not an origin problem.

References

On this page

Related solutions

Related Tools

Related guides

Related articles

Need a tool for this ?

Open the free tools — no signup.

FAQs

Innovative Solutions For Modern Needs
Copyright © 2026 Yallasolve. all rights reserved.