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.

4
  • I would run a SQL to find and replace and then write an HTTP redirection rule, if you are using Apache then with rewriteRule. Unfortunately we can't help you write codes, I suggest you experiment with the links I shared and report back with your findings. Commented Jun 26, 2018 at 5: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. Commented Jun 26, 2018 at 5:54
  • There are some plugins that can help you, for example: Velvet Blues Updates URL, WP Migrate DB or Search and Replace Plugin. Commented Jun 26, 2018 at 6:11
  • do you have database access for the old-domain? Commented Jun 26, 2018 at 6:18

1 Answer 1

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.