I have a blog that is located on a subdomain blog.example.com and I have a main website located on example.com. They both use the same wordpress template.

I'd like to transfer my blog from the subdomain to the directory of the example.com preserving 'recent posts', 'categories' and other blog-ish features.

I know that there is a plugin that allows for importing/exporting wordpress posts, but the main question is, how can I transfer those blog-ish features.

Thanks in advance.

  • Before jumping the gun with one of the below answers, taking your current environment to consideration is important. There are dozens of different setups, Amazon AWS, CPanel, Direct Admin, WP-Engine, Plesk, just to name a few. Some of these require special domain mapping What/who is your host. Oct 7, 2015 at 14:32
  • Soes "same wordpress template" mean root index.php is loading the blog located outside that directory? Are you trying to physically move the files? It is possible to leave the files alone and map the folder to a different url (similar to your current setup). Either way, always make a backup first. I personally think this plugin is the easiest if you plan on moving your whole folder as things can sometimes get messy if you didn't back up the database or sometimes hidden files or files with strict permissions don't get moved and it messes things up. Oct 7, 2015 at 14:45

2 Answers 2


You can just copy your blog files to the domain directory, then look in the MySQL database (with phpMyAdmin, say) and change the siteurl and home rows in the wp_options table to correspond to the new URL. Everything will be preserved, you might have to check and fix the often hardcoded paths to images like template logo and stuff. This is the simplest way.


Other method is to add those two lines in your wp-config.php :

define('WP_SITEURL', 'http://example.com/');
define('WP_HOME', 'http://example.com/');

Then copy the files from blog.example.com to example.com dir and finally replace all urls in database. You can do this with php script:


    // edit this line to add old and new terms which you want to be replaced
    $search_replace = array( 'http://blog.example.com' => 'http://example.com');

    //change the localhost,username,password and database-name according to your db
    mysql_connect("localhost", "root", "rootpass") or die(mysql_error());
    mysql_select_db("exampledb") or die(mysql_error());

    $show_tables = mysql_query( 'SHOW TABLES' );
    while( $st_rows = mysql_fetch_row( $show_tables ) ) {
        foreach( $st_rows as $cur_table ) {
            $show_columns = mysql_query( 'SHOW COLUMNS FROM ' . $cur_table );
            while( $cc_row = mysql_fetch_assoc( $show_columns ) ) {
                $column = $cc_row['Field'];
                $type = $cc_row['Type'];
                if( strpos( $type, 'char' ) !== false || strpos( $type, 'text' ) !== false ) {
                    foreach( $search_replace as $old_string => $new_string ) {
                        $replace_query = 'UPDATE ' . $cur_table .
                            ' SET ' .  $column . ' = REPLACE(' . $column .
                            ', \'' . $old_string . '\', \'' . $new_string . '\')';
                        mysql_query( $replace_query );
    echo 'replaced';
    mysql_free_result( $show_columns );
    mysql_free_result( $show_tables );
//    mysql_close( $mysql_link );


Good luck!

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.