Script to convert http to https for a directiory of files?
Moderator: Moderators for English X Forum
- apricotslice
- Posts: 14129
- Joined: Sun, 16. May 04, 13:01
Script to convert http to https for a directiory of files?
Anyone have a script which edits all the files in a directory structure, changing http to https?
I have several galleries created by a program long since extinct now, which wont load now due to SSL. Host says edit the files, but there are literally hundreds of them over dozens of directories.
Anyone have a script or anything which will do the conversion work?
Can be for windows, or run-able on the net.
Or alternatively, a way for getting http links to run under SSL?
Am open to suggestions, because this job is too big to do manually, but the site is still current and isn't working at the moment.
I have several galleries created by a program long since extinct now, which wont load now due to SSL. Host says edit the files, but there are literally hundreds of them over dozens of directories.
Anyone have a script or anything which will do the conversion work?
Can be for windows, or run-able on the net.
Or alternatively, a way for getting http links to run under SSL?
Am open to suggestions, because this job is too big to do manually, but the site is still current and isn't working at the moment.
Re: Script to convert http to https for a directiory of files?
I'd just use the "Find/Replace in Files" feature of Notepad++ to do this.
- apricotslice
- Posts: 14129
- Joined: Sun, 16. May 04, 13:01
Re: Script to convert http to https for a directiory of files?
Me too, but in this case, it would take weeks of mind-boggling boredom, and I no longer have the patience to do it.
20 years ago, I'd have just written a cobol program to read a directory listing in as input, and then read each file in turn and make the changes looking at every character for the target group.
Alas, my brain doesn't work properly for that any more.
- Praefectus classis
- Posts: 1504
- Joined: Tue, 14. Jan 03, 22:03
Re: Script to convert http to https for a directiory of files?
I changed my newer forum (phpbb3) to https by putting a script in the .htaccess file in the forum root directory on the server and then changing the cookie setting in the ACP to secure access. I didn't change any files.
- apricotslice
- Posts: 14129
- Joined: Sun, 16. May 04, 13:01
Re: Script to convert http to https for a directiory of files?
Care to share the .htaccess? I'll try anything.Praefectus classis wrote: ↑Thu, 13. Dec 18, 14:43I changed my newer forum (phpbb3) to https by putting a script in the .htaccess file in the forum root directory on the server and then changing the cookie setting in the ACP to secure access. I didn't change any files.
Also explain the cookie setting please.
- Praefectus classis
- Posts: 1504
- Joined: Tue, 14. Jan 03, 22:03
Re: Script to convert http to https for a directiory of files?
I put this at the top of the .htaccess file in the forum root.apricotslice wrote: ↑Thu, 13. Dec 18, 14:57Care to share the .htaccess? I'll try anything.Praefectus classis wrote: ↑Thu, 13. Dec 18, 14:43I changed my newer forum (phpbb3) to https by putting a script in the .htaccess file in the forum root directory on the server and then changing the cookie setting in the ACP to secure access. I didn't change any files.
Also explain the cookie setting please.
Code: Select all
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Re: Script to convert http to https for a directiory of files?
You have http content that contains explicit URL's and you need to modify those URL's. All of them?apricotslice wrote: ↑Thu, 13. Dec 18, 11:41Anyone have a script which edits all the files in a directory structure, changing http to https?
A recursive search-and-replace:
Code: Select all
find . -type f -exec sed -i "s/http:/https:/g" '{}' \;
Re: Script to convert http to https for a directiory of files?
I don't know "programming" but in my uses of Notepad++ and editing files, you can replace all instances of a variable string with something else. ie: Replace all http with httpsapricotslice wrote: ↑Thu, 13. Dec 18, 12:56Me too, but in this case, it would take weeks of mind-boggling boredom, and I no longer have the patience to do it...
- apricotslice
- Posts: 14129
- Joined: Sun, 16. May 04, 13:01
Re: Script to convert http to https for a directiory of files?
Yeah. But hundreds of files. I really need some automation.Morkonan wrote: ↑Fri, 14. Dec 18, 03:15I don't know "programming" but in my uses of Notepad++ and editing files, you can replace all instances of a variable string with something else. ie: Replace all http with httpsapricotslice wrote: ↑Thu, 13. Dec 18, 12:56Me too, but in this case, it would take weeks of mind-boggling boredom, and I no longer have the patience to do it...
I did this sort of thing back in my mainframe days. Write a script which creates a list, then write a program which reads in the list, processes it and spits out whatever you need, which in a lot of cases was job control language, and the script then runs the new one.
Need something like that here.
- apricotslice
- Posts: 14129
- Joined: Sun, 16. May 04, 13:01
Re: Script to convert http to https for a directiory of files?
Maybe that last part was important, because the .htaccess change had no effect. But I'm using SMF, so dont think there is that cookie thing.Praefectus classis wrote: ↑Thu, 13. Dec 18, 15:16I put this at the top of the .htaccess file in the forum root.
The secure cookie setting is the Admin Control Panel (ACP) for the phpbb3 forum but may be specific for that.Code: Select all
RewriteEngine on RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Re: Script to convert http to https for a directiory of files?
I'm unclear how the Notepad++ solution is *not* automated? You give it a directory, a file spec (e.g. *.html) and say "replace all instances of HTTP in these files with HTTPS", and it does it with a single button click. You seem to be under the impression that you have to do it one file at a time, which is not the case?apricotslice wrote: ↑Fri, 14. Dec 18, 03:47Yeah. But hundreds of files. I really need some automation.
- apricotslice
- Posts: 14129
- Joined: Sun, 16. May 04, 13:01
Re: Script to convert http to https for a directiory of files?
pjknibbs wrote: ↑Fri, 14. Dec 18, 10:11I'm unclear how the Notepad++ solution is *not* automated? You give it a directory, a file spec (e.g. *.html) and say "replace all instances of HTTP in these files with HTTPS", and it does it with a single button click. You seem to be under the impression that you have to do it one file at a time, which is not the case?apricotslice wrote: ↑Fri, 14. Dec 18, 03:47Yeah. But hundreds of files. I really need some automation.
The only Notepad I know of is windows basic text editor. So I'm assuming you're talking about something totally different? If so, link please to where I get it.
Edit: OK, found it. I had no idea it existed, and thought it was odd for there to be 2 + after the name of a basic win tool. I'll take a look.
Re: Script to convert http to https for a directiory of files?
Similarly, the "find*sed*" is a oneliner that processes every file from the specified directory tree(s). Command line tools.
Re: Script to convert http to https for a directiory of files?
Never tell any other coder that you didn't know Notepad++ existed... Never. This is imperative for your survival.apricotslice wrote: ↑Fri, 14. Dec 18, 10:22..Edit: OK, found it. I had no idea it existed, and thought it was odd for there to be 2 + after the name of a basic win tool. I'll take a look.
You will fall in love with Notepad++, though all coders bow to their own favorite editor gods, it seems.
https://en.wikipedia.org/wiki/List_of_text_editors