2

I want to replace all URLs href attribute in all my Wordpress posts body/content (over 1 million) to my new domain "Contact Us" URL like:

http://old-domain.com/any-page
http://old-domain.com/any-page-2
http://old-domain.com/any-page-3
http://old-domain.com/any-page-4

to like

http://new-domain.com/contact

Can I do this using php? Or is there any plugin for it?

I can not redirect my old domain to new domain because it is expired and I do not have access to it. I have to change URL's href attribute in every Wordpress post.

Computer User
  • 2,839
  • 4
  • 47
  • 69
  • I would run a SQL to [find and replace](https://stackoverflow.com/a/17365278/541591) and then write an HTTP redirection rule, if you are using Apache then with [rewriteRule](https://stackoverflow.com/a/1945599/541591). Unfortunately we can't help you write codes, I suggest you experiment with the links I shared and report back with your findings. – James Wong Jun 26 '18 at 05:52
  • Have you migrated your wordpress website to any other domain? if yes, then you might just need to go into your `Settings`, and go into `Permalinks` (where you change your URL format. And just hit SAVE. If it is something else then you might need to run `mysql` replace() in your DB. – Nah Jun 26 '18 at 05:54
  • There are some plugins that can help you, for example: Velvet Blues Updates URL, WP Migrate DB or Search and Replace Plugin. – drazewski Jun 26 '18 at 06:11
  • do you have database access for the old-domain? – charan kumar Jun 26 '18 at 06:18

1 Answers1

3

I recommend this great tool Search and Replace, it works like a charm, the process is as below.

  • Download the script from github.
  • Upload it into the root of your host that you can open it easily.
  • Open the URL in the browser, for example, www.yourdomain.com/Search-Replace-DB.
  • Database connection will be done automatically no need for any authentications.
  • At the top of the page there is two text fields (replace and with) add your old URL (http://old-domain.com) without forward slash at the end (/) in the replace and add the new URL(http://new-domain.com) without forward slash at the end (/) into the with field.
  • Press live run and wait until it's done.
  • Once you are done make sure you remove the Search and Replace folder (Security Reason)
Top-Master
  • 7,611
  • 5
  • 39
  • 71
RCode
  • 379
  • 3
  • 12