Script to convert http to https for a directiory of files?

Anything not relating to the X-Universe games (general tech talk, other games...) belongs here. Please read the rules before posting.

Moderator: Moderators for English X Forum

Post Reply
User avatar
apricotslice
Posts: 14129
Joined: Sun, 16. May 04, 13:01
x4

Script to convert http to https for a directiory of files?

Post by apricotslice » Thu, 13. Dec 18, 11:41

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.

pjknibbs
Posts: 41359
Joined: Wed, 6. Nov 02, 20:31
x4

Re: Script to convert http to https for a directiory of files?

Post by pjknibbs » Thu, 13. Dec 18, 12:42

I'd just use the "Find/Replace in Files" feature of Notepad++ to do this.

User avatar
apricotslice
Posts: 14129
Joined: Sun, 16. May 04, 13:01
x4

Re: Script to convert http to https for a directiory of files?

Post by apricotslice » Thu, 13. Dec 18, 12:56

pjknibbs wrote:
Thu, 13. Dec 18, 12:42
I'd just use the "Find/Replace in Files" feature of Notepad++ to do this.
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. :(

User avatar
Praefectus classis
Posts: 1504
Joined: Tue, 14. Jan 03, 22:03
x4

Re: Script to convert http to https for a directiory of files?

Post by Praefectus classis » Thu, 13. Dec 18, 14:43

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.
Reality is an illusion created by a lack of the X-universe
My new forum My original forum

User avatar
apricotslice
Posts: 14129
Joined: Sun, 16. May 04, 13:01
x4

Re: Script to convert http to https for a directiory of files?

Post by apricotslice » Thu, 13. Dec 18, 14:57

Praefectus classis wrote:
Thu, 13. Dec 18, 14:43
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.
Care to share the .htaccess? I'll try anything.

Also explain the cookie setting please.

User avatar
Praefectus classis
Posts: 1504
Joined: Tue, 14. Jan 03, 22:03
x4

Re: Script to convert http to https for a directiory of files?

Post by Praefectus classis » Thu, 13. Dec 18, 15:16

apricotslice wrote:
Thu, 13. Dec 18, 14:57
Praefectus classis wrote:
Thu, 13. Dec 18, 14:43
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.
Care to share the .htaccess? I'll try anything.

Also explain the cookie setting please.
I put this at the top of the .htaccess file in the forum root.

Code: Select all

RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
The secure cookie setting is the Admin Control Panel (ACP) for the phpbb3 forum but may be specific for that.
Reality is an illusion created by a lack of the X-universe
My new forum My original forum

jlehtone
Posts: 21801
Joined: Sat, 23. Apr 05, 21:42
x4

Re: Script to convert http to https for a directiory of files?

Post by jlehtone » Thu, 13. Dec 18, 17:55

apricotslice wrote:
Thu, 13. Dec 18, 11:41
Anyone have a script which edits all the files in a directory structure, changing http to https?
You have http content that contains explicit URL's and you need to modify those URL's. All of them?

A recursive search-and-replace:

Code: Select all

find . -type f -exec sed -i "s/http:/https:/g" '{}' \;
GNU find and sed one can install, if one doesn't have them already.

User avatar
Morkonan
Posts: 10113
Joined: Sun, 25. Sep 11, 04:33
x3tc

Re: Script to convert http to https for a directiory of files?

Post by Morkonan » Fri, 14. Dec 18, 03:15

apricotslice wrote:
Thu, 13. Dec 18, 12:56
pjknibbs wrote:
Thu, 13. Dec 18, 12:42
I'd just use the "Find/Replace in Files" feature of Notepad++ to do this.
Me too, but in this case, it would take weeks of mind-boggling boredom, and I no longer have the patience to do it...
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 https

User avatar
apricotslice
Posts: 14129
Joined: Sun, 16. May 04, 13:01
x4

Re: Script to convert http to https for a directiory of files?

Post by apricotslice » Fri, 14. Dec 18, 03:47

Morkonan wrote:
Fri, 14. Dec 18, 03:15
apricotslice wrote:
Thu, 13. Dec 18, 12:56
pjknibbs wrote:
Thu, 13. Dec 18, 12:42
I'd just use the "Find/Replace in Files" feature of Notepad++ to do this.
Me too, but in this case, it would take weeks of mind-boggling boredom, and I no longer have the patience to do it...
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 https
Yeah. But hundreds of files. I really need some automation.

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.

User avatar
apricotslice
Posts: 14129
Joined: Sun, 16. May 04, 13:01
x4

Re: Script to convert http to https for a directiory of files?

Post by apricotslice » Fri, 14. Dec 18, 04:19

Praefectus classis wrote:
Thu, 13. Dec 18, 15:16
I put this at the top of the .htaccess file in the forum root.

Code: Select all

RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
The secure cookie setting is the Admin Control Panel (ACP) for the phpbb3 forum but may be specific for that.
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.

pjknibbs
Posts: 41359
Joined: Wed, 6. Nov 02, 20:31
x4

Re: Script to convert http to https for a directiory of files?

Post by pjknibbs » Fri, 14. Dec 18, 10:11

apricotslice wrote:
Fri, 14. Dec 18, 03:47
Yeah. But hundreds of files. I really need some automation.
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?

User avatar
apricotslice
Posts: 14129
Joined: Sun, 16. May 04, 13:01
x4

Re: Script to convert http to https for a directiory of files?

Post by apricotslice » Fri, 14. Dec 18, 10:22

pjknibbs wrote:
Fri, 14. Dec 18, 10:11
apricotslice wrote:
Fri, 14. Dec 18, 03:47
Yeah. But hundreds of files. I really need some automation.
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?
:o

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.

jlehtone
Posts: 21801
Joined: Sat, 23. Apr 05, 21:42
x4

Re: Script to convert http to https for a directiory of files?

Post by jlehtone » Fri, 14. Dec 18, 15:55

Similarly, the "find*sed*" is a oneliner that processes every file from the specified directory tree(s). Command line tools.

User avatar
Morkonan
Posts: 10113
Joined: Sun, 25. Sep 11, 04:33
x3tc

Re: Script to convert http to https for a directiory of files?

Post by Morkonan » Sat, 15. Dec 18, 03:41

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.
Never tell any other coder that you didn't know Notepad++ existed... Never. This is imperative for your survival. :)

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

Post Reply

Return to “Off Topic English”