Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Brandon Brigham
Brandon Brigham
3,716 Points

Migrating WordPress site from sub folder to root folder

Hello,

All I'm simply trying to do is transfer a site in a sub folder (http://calplaygrounds.com/dev) to its root folder which is (http://calplaygrounds.com) - I am having a hard time figuring this out for some reason.

What I did initially was

(1)change the URL's of calplaygrounds.com/dev in Settings ->> General
(2) Backed up the database for calplaygrounds.com/dev which gave me an SQL and backed up website files (3) Moved all of the website files out of the subfolder (dev) and into the root folder (4) Created a new and empty database for the root folder (5) Edited the wp-config.php file to connect with the new database in root folder (6) Imported old database from original site to new one (7) Tried to access site via calplaygrounds.com/wp-admin and /wp-login and /wp-login.php

All I get is internal server errors or other errors... I don't know what I'm doing wrong..... =(

Any ideas?

Hugo Paz
Hugo Paz
15,622 Points

Your database urls are all relative to the initial folder this is one of the reasons you are getting errors.

The wordpress codex has a great tutorial for doing this. http://codex.wordpress.org/Moving_WordPress

Brandon Brigham
Brandon Brigham
3,716 Points

I have read that tutorial and did everything they said to do but am still getting errors - what do you mean they are relative to the folder?

Hugo Paz
Hugo Paz
15,622 Points

In the tutorial:

"Changing Your Domain Name and URLs

When your domain name or URLs change - i.e. from http://example.com/site to http://example.com, or http://example.com to http://example.net - there are additional concerns. The files and database can be moved, however references to the old domain name or location will remain in the database, and that can cause issues with links or theme display.

If you do a search and replace on your entire database to change the URLs, you can cause issues with data serialization, due to the fact that some themes and widgets store values with the length of your URL marked. When this changes, things break. To avoid that serialization issue, you have two options:

Only perform a search and replace on the wp_posts table.

Use the Search and Replace for WordPress Databases Script to safely change all instances. (If you are a developer, use this option. It is a one step process as opposed to the 15-step procedure below)

Optionally, you can also use an online tool (in case you don't want to bother with uploading scripts to your server) Online WordPress Serialized PHP Search and Replace which allows for replacing an old domain or URL with a new one while fixing the serialized data at the same time.

When you copied the old database to the new, you kept the old urls, this is why you are getting errors. You need to update all the urls to the new location. From (http://calplaygrounds.com/dev) to (http://calplaygrounds.com)

Eric Muhlbach
Eric Muhlbach
6,322 Points

As Hugo said you have data problems within your SQL database itself. Having tried a search and replace plugin myself that didnt work, I suggest: https://interconnectit.com/products/search-and-replace-for-wordpress-databases/ as it gets the job done nicely for me.

What you'll need to do aside from the steps you've already taken is simply use the tool as described to search your migrated DB for the old url and replace it with the new one as Hugo has described. Make sure to leave off the last trailing / on the urls IE use http://example.com/site instead of http://example.com/site/ when searching/replacing. I made that mistake once.

Good Luck!

Brandon Brigham
Brandon Brigham
3,716 Points

Right on thanks guys! I ended up starting all over from scratch which was a pain but for next time I will definitely check out your suggestions. Thanks!