Neutral Axis

One Step URL Update for Posts

by on May.12, 2009, under Uncategorized

After making a change to the URL for the blog, I discovered that links to all the photos broke. I figured the easiest way to fix them would be through editing the mysql database and managed to figure out how to change every affected link in every post in one step.

I had already installed phpmyadmin, so I put that into the browser to bring up its mysql administration page.  In the left pane, I selected the “wordpress” database and then clicked the “SQL” tab.  That brought up a box to type a command to run on the database.

The command structure was

UPDATE tablename SET tablefield = replace(tablefield,"findstring","replacestring");

I knew that the table I wanted to change was wp_posts and the field was post_content, so I used the following command.

UPDATE wp_posts SET post_content = replace(post_content,"http://oldurl:port#","");

That found all occurances of the old url and replaced them with “”, or in effect deleted that portion of the URL, leaving just the relative path.  Now if I need to change the URL again for some reason, the links should still work.


Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!


A few highly recommended websites...