How do I move WordPress from a subdirectory to the root directory?

Q. I’ve installed my website in a subdirectory of our domain, because I didn’t want visitors to see the site until I was finished with our development.

Now I want to have the site show up in the root directory (not in the http://mydomain.com/wordpress directory). How do I do this? I’ve read the information on moving WordPress, and it seems really complicated.

A. The good news is that you DO NOT need to MOVE WordPress in order to have your content display without the subdirectory name. You only need to move 1 file and change one line of code and make one modification to your General Settings, and you’re good to go (see instructions below).

Installing WordPress in a subdirectory is good idea because:

  1. It keeps your root directory clean and tidy (in case you need to add any other PHP applications to your site).
  2. It adds another layer of security by obscuring the location of your WordPress application files. Ideally, you want to name the subdirectory something not too obvious (ie don’t call it wp or WordPress). I’m not sure how obscure this really makes WordPress, because you can obviously get the subdirectory name from any images uploaded to the site, since they will still read as sitename.com/subdirectory/wp-content/uploads/image.jpg, so I usually install WP in a subdirectory for development purposes or to simply keep the root directory clean in case I install any subdomains or other applications.
  3. It allows you to develop a new WordPress site while maintaining your current website in the root directory. Once you’re finished with your WordPress development, you can backup and then delete your current site’s files, and use the following instructions to display WordPress from the root directory of the site.

“Moving” WordPress from Subdirectory to the Site’s Root Directory

1. Install WordPress as you normally would, but instead of installing it in the root directory (ie in the www or public_html directory), install it in a subdirectory in the www or public_html folder. Before continuing with this process, I highly recommend:

a) de-activating caching, broken link checker and any redirection plugins;

b) removing any old site files from the root directory — perhaps copy them to a folder called _backup;

c) making sure you don’t have any other folders in the root directory that have the same name as any pages on your WordPress site, for example “blog” unless of course this is the name of your subdirectory install of WordPress in which case you cannot have a page of the same name because the browser will get confused and look for that page in that folder, then things are really confused;

d) using wp-db-backup to make a backup of your database;

e) getting access to your database via phpMyAdmin on your web host’s control panel in case you type the URLs wrong in the next step. Your database username and password are in the wp-config.php file.

2. Once you’ve completed your design work, adding pages to the site, etc., login to the WordPress Dashboard. From the Settings -> General tab, set your WordPress address URL to the subdirectory you installed WordPress in (without the trailing slash). Note: This will already be displayed in the WordPress address field, so you don’t have to change it. What you do need to change is the Site address URL. Set this to  your site’s root address (without the trailing slash).

3. Next, using an FTP application or your web host’s File Manager, DOWNLOAD the index.php file that is in the WordPress application directory (not the one in your theme’s folder or elsewhere) and then UPLOAD the copy you downloaded to the root directory. (By root, I mean the www, htdocs, or httpdocs folder — NOT the root of your hosting account! You simply want to upload the copy of the index.php file and put it in the parent folder of your subdirectory which presumably is the location for the main URL of your website.)

Alternately, you can use your FTP application and MOVE the index.php “to the parent” but then you MUST read and follow step 6 below.

(Note: If you have a site already in the root directory, such as an old static html site, then you should backup and delete those files first.)

4. In a text or HTML editor, open the index.php file that you just copied and/or moved to the root (aka main url) directory and change the location of your wp-blog-header.php to tell WordPress where it can find the WordPress application files in the subdirectory:

Example: if your WordPress installation folder is ‘mywp’, you would change:

<?php require('./wp-blog-header.php'); ?>

to

<?php require('./mywp/wp-blog-header.php'); ?>

Important: Be sure you type this correctly! A missing / or too many slashes or missing period or apostrophe can make this not work. Believe me, I’ve seen people be totally freaked out things didn’t work and it was because they typed this line wrong.

5. Visit the site and click an interior page to make sure it displays correctly. If it doesn’t, you may need to update your permalinks (Settings -> Permalinks and click Save Changes). If you still cannot access your interior pages, then the .htaccess may need to be moved to the same location as the index.php file (i.e. the root directory). This is not necessary on all web hosts. Be sure to update the permalinks again after you move the .htaccess file.

Remember that your login and registration links will still be http://www.yoursite.com/mywp/wp-login.php.

Now, when people visit your site, they will see all the URLs of all the pages and posts as if you had installed WordPress in the root directory, and you will have a neat WordPress directory behind the scenes.

6. Create a “Silence is Golden” index.php file in the WordPress directory.

If you copied the index.php file instead of moved it, this step is optional. Essentially, you don’t “need” this duplicate index.php file in the subdirectory because it doesn’t really do anything other than prevent people from reading the directory contents. However, if you moved the index.php file leaving the WP directory without an index.php file, then you should create a new blank index.php file and put the following code in the file:

<!--?php // Silence is golden. ?-->

Alternatively, you can install the Silence is Golden Guard plugin, which provides a lot of other useful security tools as well: http://wordpress.org/extend/plugins/silence-is-golden-guard/

A Note About Using Cforms if WordPress is Installed in a Subdirectory

If you are using Cforms contact form plugin for WordPress, you will need to tell the Cforms javascript that Cforms is in a subdirectory. You’ll want to do this BEFORE you activate the Cforms plugin. Hyperarts.com created a good post about how to do this:

Telling Cforms JS that WordPress is installed in a subdirectory

A Note About Web Hosting

If you have a current site with a non-WordPress friendly host, you may want to set up hosting with a WordPress friendly hosting company and move your current site’s files to the new host and then install WordPress as instructed above.

Problems?

If you have any trouble with this process, please visit my FAQ at: http://askwpgirl.com/moving-wordpress-from-subdirectory-to-root-faq/

Please comment on that page.

Success?

If this process was successful, please comment with a thumbs UP below, share on Twitter, follow me on Facebook. Thanks!!!

  • Anonymous

    Awesome!

  • Anonymous

    Very good. Be sure to check any internal links to pages you may have made, so they link to the new url for the pages.

  • Anonymous

    hey girl.. i have alot of questions since it seems..you are so good in WP.. i hope its ok to ask it here…

     umm i have a webhosting server on Ninja Lion and im using 2 domains on that server..its ok right? thats the first question :P lool

    2nd, im going to link my website on a facebook page..but the problem is ..that the posts i made on the site have a featured imaged as usual..these images do not appeare on fb when i post them.. how can that be fixed? any plugins to suggest?

    3rd, how can i change mywebsite.com/wp-admin to mywebsite.com/somethingelse/wp-admin so to be more secured?

    4th.. .htaccess should be configured manually ? or by it self..although i know nothing about it.. 

    those are few questions.. yet i have more.. but i dont want to bother you alot hopefully im gonna solve the rest..if not..then i have to ask you again lool :) . sorry for bothering.. thanks alot

    MadBoy

  • Anonymous

    Okay, MadBoy, I’ll try to answer your questions here simply:

    1 – Hosting. Most web hosts do allow you to host unlimited domains on the same hosting account. You have to find out if they “throttle” your bandwidth at all based on hits or downloaded content. Otherwise, it’s fine.

    2 – When you manually post a link to your website on Facebook, it looks at any of the images on the page to use as the post thumbnail. However, if the only images on the site are background images in the CSS, then it won’t find an image. It actually has to be an image inserted on the post/page or sidebar — not in the CSS.

    3 – I don’t think I would bother. There are many other things you need to make your site more secure, such as have strong passwords, use a backup plugin like BackupBuddy (http://askwpgirl.com/go/backupbuddy.php), don’t use vulnerable themes and plugins. There are too many ways a hacker can figure out what directory your files are in, so other security measures are more important. You’re not going to prevent your site from being hacked if you are using a vulnerable script or plugin simply because WP is in the subdirectory.

    4 – A couple purposes for the .htaccess: 1) to make the pretty permalinks work. Usually clicking Save Changes button on the Permalinks settings page will auto generate the .htaccess file. If not, you can create it using an ftp application that is set to view invisible files and give it 644 permissions. Then WordPress can write to it. 2) to make your site more secure, manage page cache, and do redirects. For security, you can try the BulletProof Security Plugin which locks down the WP site via .htaccess.

    I hope that helps!

  • Jagesh M

    what is the difference between wordpress address url and site address url?

  • Anonymous

    The WordPress Address URL is the URL where the WordPress application is located. The Site Address URL is the address from which you want the pages and posts of the site to be displayed from. The purpose of this post is to show you that you can have the WordPress URL be in the subdirectory, and the Site URL be in the directory above that (ie the root website address), and still have WordPress work. The trick is to move the index.php file that’s in the subfolder where WordPress is located to the parent folder and then edit it to show where WordPress is located. See the instructions in this post for more details.

  • Paul

    Hi, I tried implementing this but got this message:
    PHP Warning: main(/index.php): failed to open stream: No such file or directory in D:Domainszzz.comROOTInetpubwwwrootblogwp-404-handler.php on line 7 PHP Warning: main(): Failed opening ‘/index.php’ for inclusion (include_path=’C:WINDOWSsystem32inetsrvphppear’) in D:Domainszzz.comROOTInetpubwwwrootblogwp-404-handler.php on line 7
    wp-404-handler.php is used as I have Windows server and IIS. wp-404-handler.php is in the sub-folder blog:-
    How to change the index.php in this to the new file in the root?

  • MucaLuca

    WOW! I normally don’t take a woman’s advice on most things, but I have to say; this reads well so far and seems to make sense. I’ll be trying this out as soon as I’m done with my project.

  • Anonymous

    I’m not sure if I should be flattered or offended. Why in the world would you not read technical documentation by a woman? The ability to write technical documentation has nothing to do with someone’s genitals. Men are just as capable of writing total crap as women are. Anyway, I’m glad it will be helpful to you.

  • Anonymous

    Hi Paul,

    Hmmm…. I have no idea where to start here. I’m working on writing an FAQ, because the only times I’ve seen this process not work is when someone doesn’t follow the steps exactly as written. So, first answer the following questions for me:

    1 – Where did you put the index.php file and what do you have in the “require” line of the index.php file?

    2 – Are you able to login to the WordPress Dashboard?

    What is your domain name? You can certainly email me directly via my contact form.

    Thx.

  • Jade

    :( I followed the instructions exactly and all I’m getting is a white page that says I can’t access the site. Any ideas?

  • Anonymous

    Hey Jade,

    I wrote you an email with some suggestions of things to check. I’m going to write an FAQ for this post, because I have discovered that people do make errors in the process even when they believe they have followed the instructions “exactly.” They are usual simple errors, and we can get it resolved quickly.

  • Paul

    Thanks, I’ve emailed separately but had missed out the important step 2. Now the PHP error message goes away but the permalink, without the subfolder in the URL, cannot be found. It goes to our custom site-wide ASP error file, and not the error file created for the blog folder only, wp-404-handler.php, in cases like this where Windows hosting does not allow .htaccess rewrite.

  • Anonymous
  • Anonymous

    I just wrote an FAQ that might be helpful. You could be having a PHP issues with your .htaccess:

    http://askwpgirl.com/moving-wordpress-from-subdirectory-to-root-faq/

  • Anonymous

    Hi Paul — WINDOWS HOSTING – run as fast as you can! It’s truly horrible, but you should talk to your web host, because they can enable this functionality on the server. It’s not impossible, but they will need to do it. Give them a call and see what they have to say. In the meantime use the default permalinks. I think if you move the .htaccess to the public_html that might help, and you may need to include the /index.php in the permalink structure. Here are more details about the permalink structure you can speak with your host about:

    http://codex.wordpress.org/Using_Permalinks

  • Jeanteena

    Hey… I went through this method Step by Step and It worked!! But however, my comment form is missing from my posts ever since. I do have the “Leave the Comment” still on my page. please help.

  • Anonymous

    Hi Jeanteena,

    Wow, that is strange. It sounds like perhaps there is something with the theme not knowing where to find the comments template. That usually shouldn’t be effected by the subdirectory change. Do you want to zip up your theme file and email it to me? If you email me via my Contact form, I can reply to you. Some themes are not coded properly, and they have URLs to their internal template files that are relative to the wrong thing.

  • Aneesh

    Hi,
    My WP installation is in a sub-directory and I want to move to the root. But my server is Windows 2003. Can I follow the same steps? Please advise.
    Thank you.

  • Anonymous

    Hi Aneesh,

    This process will work just fine with the possible exception of the “pretty” permalinks working as expected. Do you have permalinks enabled on the current site or the default permalinks (Settings > Permalinks)? The nice thing is that you can certainly try the process, which if you follow exactly only takes a few minutes. If it doesn’t work, then you can reverse the steps by first changing the General Settings back to what they were and then moving the index.php file back to the subdirectory and editing it again.

    Please read this post from the WordPress codex on enabling permalinks on Windows: http://codex.wordpress.org/Using_Permalinks#Permalinks_without_mod_rewrite

  • jeni

    YAY – this does indeed work like a charm – thank you !

    jeni

  • http://madebyfirefly.com Rachel

    Thanks a mil!
    Work perfect – best and easiest instructions out there.
    =)

  • Anonymous

    You’re welcome. Yay!!!

  • Nate

    Thank you so, so much for this. You just saved me tons of time and stress. You are great.

  • Anonymous

    Hey Nate – Thanks for the comment! I hope it all works out for you.

  • Anonymous

    My instructions assume that people are running on an Apache server rather than some not-so-friendly web hosting package such as Windows or Zeus. Apache/Linux is the best environment for WordPress and WordPress plugins to run. If the host is not running Apache/Linux, then permalinks do cause an issue, and you have to check with your web host about how to enable the rewriting of the IDs to the pretty permalink structure, whether via a web.config file on Windows or the Zeus rewrite you mentioned for Zeus servers. I’ll be sure to edit the post to differentiate these different hosting environments.

    This post is primarily about “moving” WordPress, but in the process, people will activate the pretty permalinks and have them not work and assume it’s because of the “move” when it was because they didn’t realize that their host didn’t support permalinks for Apache server.

  • Chris

    Hey, I found a completely free plugin that automates this entire process. It moves the files and the database and everything automatically. Here it is: http://www.movewordpress.com/

  • Anonymous

    This process I describe is NOT for “moving” aka “migrating” WordPress. This process is for deliberately installing WordPress in a subdirectory (for development purposes) and then having it show in the root. You do not need to touch the database or “move” anything other than the index.php file.

    For “migrating” WordPress, I recommend that people purchase BackupBuddy (http://askwpgirl.com/go/backupbuddy.php) which does backup the database and the files and allow you to easily migrate the site to a new server. It can also be used to schedule regular backups of the site to cloud storage or other FTP server. I’ll check out this free plugin, too! Always nice to know about these tools.

  • Debisykes

    Thanks that is so useful! you saved me a massive headache in trying to update all paths in my database!

  • Anonymous

    Yay!

  • A Happy Developer

    Thank you, thank you, thank you!  You saved me so much work.  I am so happy I found your post.  I tried to do this the hard way, and wasted hours.  If only I had found your solution first!

  • geekoffline

    Hi there,

    Thank you for an excellent ‘how to’.  As a new wordpress blogger, I was quite perturbed to find myself displaying my root www directory when I went to my site.
    All sorted and working thanks to you.

  • Anonymous

    Hi Charlene,

    Two things:

    1 – With this process, you will still login at the full URL that includes the subdirectory because the WordPress application is still located in the subdirectory. We did not move WordPress, we simply made the page and post links display from the root.

    2 – To avoid having people index the subdirectory (ie to keep the subdirectory contents private), you need to follow step 7 on this blog post: http://askwpgirl.com/moving-wordpress-from-subdirectory-to-root-faq/

    Good luck!

  • Anonymous

    I don’t think there is any advantage to having the site be in the old Joomla directory since all the URLs are going to be from the root anyway. However, you might want to use the WordPress Redirection plugin to redirect those old URLs to the new ones on WordPress. http://wordpress.org/extend/plugins/redirection/

  • Anonymous

    Hi Grey, It sounds like you’re really on top of your content needs and thinking ahead of the curve. I don’t know if multi-site is the solution for you or not, but I think custom post types could be an easy way for you to go. Though it sounds like you want to limit searching to just within the custom post type of the product they care currently browsing. There are some forum posts on on WordPress.org on how to limit searching to specific custom post types, but then you’d want to create multiple searches. I’ve been using drop down taxonomies for something similar — so they can pick the “product type” they want from the drop down, and I have 5 different ways products are categorized. So you may need more custom taxonomies rather than custom post types if that makes sense. Good luck!!!

  • Anonymous

    Yay!!! I’m so glad to hear that.

  • Anonymous

    Happy New Year, Walter and Chris. Thanks for the greetings. Cheers! You’re music is wonderful. I love it! I volunteer with a West African dance/drumming festival and visited Ghana a couple years ago. I’m a big fan of Ry Cooder, and your music reminds me of his CD Talking Timbuktu with Ali Farka Toure.

  • Brian Saemann

    Thank You…Thank You…Thank You…

    Excellent, easy to follow instructions. This worked like a charm!

  • Birokrat

    Angela I’m having problem with the permalinks they are still pointing to my subdirectory

  • Anonymous

    Hi — Try to set your permalinks to the default and see if the pages work and let me know. Then, I can tell you what to check next.

  • Anonymous

    Awesome!

  • http://twitter.com/WalterMatyas Walter Matyas

    Thank you for the nice tips . I have followed the steps in “How do I move WordPress from a subdirectory to the root directory?” and my pages still show url inside the subfolder. Do you know why? http://drangelebesner.com

  • Anonymous

    Hi Walter. Looks like you didn’t follow all the tips exactly. Please read the post again and then perhaps read the FAQ and make sure you got it all step-by-step. Also check your permalink structure. Should not include the sub-directory name in that structure.

  • Cmyers1130

    I am updating a site for someone who originally had another person working on it.  He is not knowledgeable with website development.  I have never used WordPress before this.  Well, today I was playing with a URL change to just point to a different page.  I went back afterwards to the General area and changed it back since it didn’t work.  However, now I can’t access WordPress at all.  I get the Internal Server Error.  I don’t have access to the PHP area on my computer to change anything in the database.  He doesn’t even have the WP install on his computer.  I guess the previous person did all that.  So, is there anyway for me to fix this or anyone who I can contact to do so?

  • Anonymous

    You will need to get his web hosting control panel and FTP access to the site. Once you get the web hosting control panel access, you can login to phpMyAdmin which is an application you’ll see in the control panel. If it asks you for a password, you’ll need to have the FTP access to the site to find the database username and password in the wp-config.php file. Read the FAQ I have to this post for more information. Email me directly via my contact form if you get stuck. I charge $75/hour for support, and generally these issues are resolved in under an hour — usually 15-30 minutes.

  • Pingback: And, Wordpress hackers, just in case you’re interested… | Computer Floss

  • BDA

    Hi WPGirl,

    I would like to change my existing site substantially but need to work on these changes while the current site remains up for users.  The switch from current site to new site would need to be pretty seamless in timing.   Is it right to assume a second wordpress install to a subdirectory is a good way to work on a new site while the current site is up? 

    Would your instructions above allow me to ‘move’ the new site in the subdirectory to the current/old sites url?  Sorry if my language is fuzzy but I’m obviously a bit green here, hopefully you understand what I’m asking :)  

    With that said, where would the best instructions be found for installing wordpress into a subdirectory?  I ask you simply because I want to make sure I set this up properly for your instructions!

    Thank you for your time,
    BDA

  • Anonymous

    Hi Bobby,

    Yes!!! That is exactly what I do for current clients. Right now, I am redesigning a site for a client, so I used BackupBuddy plugin (http://askwpgirl.com/go/backupbuddy.php) and I did a full backup of the current site, created a new blank database, and then ftp’ed the backupbuddy backup plus their importbuddy.php script to the subdirectory where I’ll do the development on the new site, then ran the importbuddy.php script via the domainname/subdirectory/importbuddy.php url.

    The beauty of backupbuddy is that it will update ALL the links and URLs, so they reference from the new location of WordPress in this new subdirectory.

    So, then after you’ve “migrated” your current installation using backupbuddy to the new subdirectory, you can do all your modifications. When you’re finished, you can follow the steps in this post to have the pages from this subdirectory installation display from the root, so you all of the URLs will match the URLs as they currently are on the old site with the exception of images, which will all link via the subdirectory URL.

    The beauty of this process is that all of your image links will not be effected when you do the “move.”

    So, definitely use BackupBuddy to get the copy of the current site duplicated in the subdirectory correctly — unless you’re basically blowing away the current site and are starting fresh.

    Feel free to email me via my contact form if this is at all confusing. Once you’ve done backupbuddy migration a few times, you can do it in your sleep or like I do — in a sort of half awake over-caffeinated zombie like state.

    Cheers,
    Angela

  • Jerry OConnor

    Hi Wp Girl,

    Currently my Wp develpoment site is in a seperate directory of the site root directory. The old site, which I will be removing, is in the root directory.

    Your instructions are the most lucid I have come accross, but I found almost identical instructions at http://codex.wordpress.org/Giving_WordPress_Its_Own_Directory, and there seems to be a conflict.

    You say, “MOVE (do not copy) the index.php file,” and the other instructions say, “Copy (NOT MOVE!) the index.php.” In addition, the other instructions mention moving the .htaccess file to the root directory. Can you comment on this?

    I could just experiment a little, bu I am fearful of digging a hle I can’t get otu of.

  • Anonymous

    They suggest copying instead of moving, because when you move the index.php file from the subdirectory it leaves your subdirectory without an index file meaning that visitors can look at all the files in that directory. I have had best success with moving the file. If you copy it, people often edit the wrong file, try to access WordPress in a way they shouldn’t, etc. It’s just messy to leave a copy in the subdirectory.

    After you MOVE the file, you’ll want put a blank “Silence is Golden” index.php file in the subdirectory so people can’t view your subdirectory contents. I describe how to do this in this post. You can find a “Silence is Golden” index.php file in the wp-content folder, the themes folder, and the plugins folder. It is in all of those folders to keep people from seeing the contents of those folders. If you open one of those index.php files, you’ll see some text that says “Silence is Golden.” It just is there as a non-displaying comment and results in a BLANK page being displayed when someone goes to the URL of that directory. Try it.

    So, the wordpress.org instructions are not “wrong” per se, they are just not “correct” if you want to do things cleanly. I think they realize most people can’t handle too many steps in a process and don’t want to leave the subdirectory without any index file for security reasons. Make sense?