Cookie Consent by Free Privacy Policy Generator Convert your sitelinks to https with sed | Igor Moiseev

Igor Moiseev Applied mathematician, Web Developer

Convert your sitelinks to https with `sed`edit

I’ve wrote before the small post on how to find and substitute the string in all files with sed command in GNU/Linux. Now I’d like to show the real use case.

You’ve bought a new SSL certificate and configured your web server. After you fire it, you can make an unfortunate discover when you open the browser on your brand new, that it says “Some parts of this page are not secure”.

So what is insecure? Simply you may have used the insecure contents like images or external JS libraries loaded from CDN.

To help with this, Linux has a small and powerful command to find and substitute the old_phrase with the new_phrase in all files and directories recursively - it is sed command on GNU/Linux

find . -type f -print0 | xargs -0 sed -i 's/old_phrase/new_phrase/g'

Attention! The previous command finds files also in the hidden folders and if you’re working with Subversion or GIT you’d like to skip them. The following keys -not -path '*/\.*' makes the trick

find . -not -path '*/\.*' -type f -print0 | xargs -0 sed -i 's/http:\/\//https:\/\//g'

After this command your links like

<img src="">

will be converted to

<img src="">

Happy coding! is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means to earn fees when linking to and affiliated sites.