Answer the question
In order to leave comments, you need to log in
How to replace internal links in the database with https?
There is a table with several thousand records (publications). It is necessary to check if there are links (internal) through in the body of the publication http
and replace this http
one with https
.
I made a console command that gets all the id of publications and in a cycle foreach
through the regular expression (I used AR) replaces the necessary one, after which I save the record.
Can it be done smarter?
Answer the question
In order to leave comments, you need to log in
Well, at least do not use AR - this task is much easier to solve with a simple sql query - select the id and the text in which you want to replace.
If you are careful and with a backup, you can use the MySQL REPLACE function:
https://stackoverflow.com/questions/5956993/mysql-...
https://dev.mysql.com/doc/refman/5.7/en/string- fun...
PS It won't work with WordPress, it has its own crutches!
A small offtopic: It is advisable not to replace it with ` https://`, but simply replace all occurrences of ` http://` with `//`
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question