Before an HTTPS Migration, Find Protocol-Relative Links That May Change Their Destination

Find protocol-relative URLs before an HTTPS migration, check how they resolve, and verify redirects, certificates, and resource behavior.

Published
Reading time
6 min read
Before an HTTPS Migration, Find Protocol-Relative Links That May Change Their Destination
On this page

Protocol-relative URLs such as //cdn.example.com/app.js do not specify HTTP or HTTPS. During an HTTPS migration, the same reference can start requesting a different URL without any change to the reference itself. That can expose certificate problems, different server responses, or unexpected redirects.

This workflow helps you find those references, resolve them in their actual context, and decide what to change before moving a site to HTTPS.

Key Takeaways

  • A protocol-relative URL inherits a scheme from its base URL; on a typical HTTPS page, it resolves to an HTTPS URL.
  • The hostname usually stays the same, but the scheme change can lead to a different response or a failed request.
  • Search source files and content exports, then check rendered pages and network requests. Text searches alone will miss some generated or encoded references.
  • Check the actual base URL: an HTML <base> element or an external stylesheet can change how a reference resolves.
  • Verify important destinations, redirects, certificates, and resource behavior before replacing references.

How protocol-relative URLs resolve

Assume a page at http://www.example.com/products/ contains the reference //cdn.example.com/app.js. Its resolved URL is http://cdn.example.com/app.js. If the same reference uses an HTTPS base, it resolves to https://cdn.example.com/app.js.

Compare three kinds of reference on a typical HTTPS page:

ReferenceTypeResolution
//cdn.example.com/app.jsProtocol-relativeUses the base scheme and the specified host: https://cdn.example.com/app.js
https://cdn.example.com/app.jsAbsoluteUses the specified scheme and host
/app.jsRoot-relativeUses the base scheme and host, with a path starting at the root

A change in scheme changes the URL's origin even if the hostname remains the same. The HTTPS endpoint might serve different content, redirect somewhere else, require different authentication, or fail because its certificate or server configuration is unsuitable. Resolving a URL does not establish what the server will return.

For HTML references, the effective base is normally the document URL, but a <base href> element can override it. For a URL inside an external CSS file, resolution is relative to the stylesheet's URL. Inline styles use the document's base context. Check the actual context rather than assuming every // reference inherits directly from the page address.

Advertisement

Inventory references before the migration

Search a local copy of the site and its content exports. Include:

  • HTML, templates, components, and server-rendered views.
  • CSS files and inline styles, including url() and @import references.
  • CMS exports, stored rich text, Markdown, configuration, and localization files.
  • JavaScript that constructs URLs or inserts elements, as well as generated HTML and CSS bundles that will actually be deployed.

For a broad first pass, you can use ripgrep against a local export or project directory:

rg -n --hidden --no-ignore -F '//' ./site-export

This is an inventory aid, not a precise URL detector. It also matches https://, comments, and other non-URL text. It can produce a large result set; review generated files and dependencies as appropriate, and avoid exposing sensitive export contents in shared logs. Replace ./site-export with the directory you are authorized to inspect.

A literal search can miss encoded or generated references. For example, JSON may represent slashes as \/\/, and HTML entities or JavaScript concatenation can hide the literal //. Search the relevant source formats as well as decoded exports, and inspect rendered pages for references created at runtime. Ripgrep may skip binary files; inspect any relevant non-text exports with the tool that produced them.

For each candidate, record its source location, resource type, effective base URL, expected HTTPS resolution, owner, and whether the destination was verified. Pay particular attention to scripts, stylesheets, images, fonts, iframes, form actions, links, and CSS imports.

Verify resolved destinations

Use an HTTPS staging environment that closely represents production. Check representative pages, templates, and content types, including pages that load resources after interaction.

  1. Open a page in a browser and inspect the element or stylesheet containing the reference. Note any HTML <base href> and, for external CSS, the stylesheet URL.

  2. Resolve the reference against that base. For an HTML element, the browser console can show the document's effective base with document.baseURI. You can also evaluate a specific example:

    new URL('//cdn.example.com/app.js', document.baseURI).href
    

    For a reference in an external stylesheet, use that stylesheet's URL as the second argument instead of document.baseURI. Substitute the actual reference and base you are reviewing.

  3. In the browser's Network panel, reload the page and inspect the request, its status, and its redirect chain. Check the final destination as well as the initial resolved URL. Repeat after interactions that load additional content.

  4. Confirm the HTTPS endpoint presents a valid certificate and returns the intended resource. Check browser console messages for failures involving mixed content, cross-origin access, content security policy, or integrity checks where those controls apply.

  5. Compare important behavior with the existing HTTP site. Authentication, cookies, redirects, and resource contents can differ between the two endpoints. An HTTP-to-HTTPS redirect, browser upgrade behavior, or cached response can make a comparison misleading, so inspect the actual requests.

Use only sites and environments you own or are authorized to test. Do not paste credentials or private URLs into an online tool or a shared issue tracker.

Verification limitation: The WHATWG URL Standard was not available to consult for this draft, and the examples were not tested in current browsers here. Before publishing or using the results as a migration sign-off, consult the standard and run the checks above in the browsers you support.

Advertisement

Choose a replacement deliberately

For an external resource that is intended to load over HTTPS, an explicit URL such as https://cdn.example.com/app.js makes the intended scheme clear. Verify that endpoint first; changing the text does not fix a missing certificate, unsupported resource, or redirect to HTTP.

For a resource intended to stay on your own site, a root-relative reference such as /assets/app.js can be appropriate. It follows the effective base's scheme and host, so confirm the effect of any <base> element and whether staging and production use the expected host.

Do not automatically convert every // match. Some matches are not URLs, and some references intentionally point to a different host. External assets may be controlled by another organization; coordinate changes and verify them in staging before deployment.

Common Mistakes

  • Searching only HTML files. Templates, CSS, CMS content, and runtime-generated elements can introduce additional references.
  • Treating every match as a protocol-relative URL. Absolute URLs and comments also contain //.
  • Checking the hostname but not the scheme or redirect chain. The resolved HTTPS URL and final response both matter.
  • Assuming the page URL is always the base. HTML <base> elements and external stylesheets can change resolution.
  • Replacing all matches without review. A bulk edit can change third-party destinations or corrupt non-URL text.
  • Assuming a successful request proves the migration is complete. Exercise pages and interactions that depend on the resource, and check browser errors.

Best Practices

Keep the inventory with the migration work, assign an owner to external dependencies, and record the chosen replacement or reason for retaining each reference. Repeat the source search and browser checks after changes, then monitor for failed requests and redirects after deployment. Add a review or automated check for new protocol-relative references where your project's tooling permits it.

Conclusion

Protocol-relative references can silently switch from HTTP to HTTPS when their base changes. Find them across source and content, resolve each against its real base, and verify the resulting request before deciding whether to use an explicit HTTPS or root-relative URL.

What would your domain sell for?

A free TidyURLs account unlocks the Domain Estimator. It prices a name from 191,011 real domain sales.