To change http to https in all your website files, run a find and replace across every HTML, CSS, JavaScript and PHP file in the site folder, replacing http://yourdomain.com with https://yourdomain.com (and the www form). Do your own domain first, then review the remaining http:// links one by one rather than blindly changing all of them. Afterwards, check pages in the browser for mixed content warnings.
This guide covers what to replace, what to leave alone, patterns that catch every form of your domain, and how to confirm the move is complete.
Why hard-coded http links matter after moving to https
Once your site has a certificate, any page loaded over https that pulls in an image, script, stylesheet or font over plain http has mixed content. Modern browsers block mixed scripts and stylesheets outright and upgrade or flag other resources, which can break layouts and features or remove the padlock. Plain links to your own pages over http also cost an extra redirect on every click and send mixed signals to search engines.
Redirecting http to https on the server is essential, but it does not fix references written into your files. Those need a find and replace.
Step 1: back up and list what you have
- Copy the site folder or commit it to version control.
- Search the whole tree for
http://and note the count. - Search again for
http://yourdomain.comandhttp://www.yourdomain.com. The difference between the counts is links to other sites, which you will handle separately.
Our guide to finding all files containing text on Windows shows quick ways to get these counts with findstr or PowerShell.
Step 2: replace your own domain
For a plain-text replace, run two rules, longest first:
| Find | Replace with |
|---|---|
http://www.yourdomain.com | https://www.yourdomain.com |
http://yourdomain.com | https://yourdomain.com |
Or do both in one regex rule:
- Find:
http://((www\.)?yourdomain\.com) - Replace:
https://$1
Notice the escaped dots. Without the backslash, . matches any character. Include every extension that can contain URLs: .html .htm .php .css .js .json .xml .txt, plus templates and config files your site uses.
Escaped URLs in JSON and JavaScript
JSON files and some JavaScript store slashes escaped, so a URL looks like http:\/\/yourdomain.com. A search for http:// will not find those. Add a second rule:
- Find:
http:\/\/yourdomain.com(plain text) - Replace:
https:\/\/yourdomain.com
As a regex the find becomes http:\\/\\/yourdomain\.com, because each literal backslash must itself be escaped.
Step 3: handle third-party links individually
It is tempting to replace every http:// with https://. Do not do it blindly:
- Most major sites serve https, but some older sites do not, and a few serve different content or errors over https.
- Some
http://strings are not links at all, such as XML namespaces likehttp://www.w3.org/2000/svgandhttp://www.w3.org/1999/xhtml. These are identifiers and should stay exactly as they are. - Documentation and code samples may show http on purpose.
Review the remaining matches, group them by domain, test each domain over https in a browser, and add a rule per domain that works.
Step 4: check for leftovers
- Search for
http://yourdomainandhttp://www.yourdomainagain. Both should return zero. - Open key pages in the browser, press F12, and check the Console tab for mixed content warnings.
- Check pages that load fonts, maps, video embeds or analytics, which often hide http references.
- If warnings remain but your files are clean, the URL is coming from somewhere else: a database, a CMS setting, or a script that builds URLs.
Doing it in one checked run
A site move is a typical job for a batch tool because it combines several rules, a large folder tree and a strong need to check before saving. In Bulk Replace:
- Choose the site folder, include sub-folders, and filter to
.html .css .js .phpand any other extensions you use. Images and other binary files are skipped automatically. - Add the domain rules above as stacked rules: the www form, the bare form and the escaped JSON form. Use regex for the combined pattern if you prefer.
- Preview. The before/after diff lists every file with its match count. Untick any match you want to leave, such as a code sample.
- Apply. Each file is backed up first, and one click undoes the whole run if something looks wrong.
Bulk Replace keeps each file in its original encoding, so pages with accented text or symbols are not damaged by the rewrite. The CSV report gives you a record of exactly what changed, which is useful if a client or colleague asks later.
The same change with PowerShell
If you prefer a script, this replaces both forms of your domain in every common web file under the current folder. Back up first, because it overwrites files and has no undo:
Get-ChildItem -Recurse -File -Include *.html,*.htm,*.php,*.css,*.js,*.json,*.xml | ForEach-Object { $t = Get-Content $_.FullName -Raw -Encoding UTF8; $n = $t -replace 'http://((www\.)?yourdomain\.com)','https://$1'; if ($n -ne $t) { Set-Content $_.FullName $n -NoNewline -Encoding UTF8; $_.FullName } }
Keep the replacement in single quotes so PowerShell does not treat $1 as a variable. In Windows PowerShell 5.1, -Encoding UTF8 adds a byte order mark to files that did not have one, which some PHP setups dislike. Our PowerShell replace guide explains how to avoid that.
Where http references hide
- CSS:
url(http://...)for background images and@importor@font-facesources. - JavaScript: API endpoints, analytics snippets and strings that build image URLs.
- HTML attributes beyond
hrefandsrc:srcset,actionon forms,data-attributes and inlinestyleattributes. - Meta tags: canonical links, Open Graph and Twitter card images.
- Feeds and sitemaps:
sitemap.xml, RSS and Atom files.
A search across all text file types, rather than just .html, finds these in one go.
Protocol-relative URLs: should you use //?
An older technique is to replace http:// with // so the browser uses whichever protocol the page uses. On an https-only site that just means https, so writing https:// explicitly is clearer and is now the common recommendation. Protocol-relative URLs also fail when a page is opened from disk with file://.
Other places to update
- Canonical tags and sitemaps. Make sure
<link rel="canonical">and every URL insitemap.xmluse https. - Open Graph tags. Update
og:urlandog:image. - Server config. Add a permanent (301) redirect from http to https, and consider HSTS once everything works.
- Search Console and analytics. Add the https property and update the site URL.
If you are changing the domain at the same time, follow our guide to replacing an old domain with a new domain in website files, which covers email addresses and every URL form. And if you are new to patterns like $1, see regex replace with capture groups.
Frequently asked questions
Should I replace every http:// with https://?
No. Replace your own domain first, then check third-party links one by one, because not every external site serves the same page over https.
Will protocol-relative // links work instead?
They work, but on an https site they simply load over https. Writing https:// explicitly is clearer and is the usual recommendation today.
Why do I still get mixed content warnings after the replace?
Some http references live outside your files, such as in a database, a CMS setting or a script that builds URLs. Use the Console in your browser's developer tools to find the remaining requests.
