1. 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).
2. 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.)
3. 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:
require( dirname( __FILE__ ) . '/wp-blog-header.php' );
require( dirname( __FILE__ ) . '/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.
4. 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.
Note: If the site you are redirecting to the root previously was your live site, and you have a lot of posts whose URLs you do not want to change, then you should change your Permalink structure to INCLUDE the old subdirectory name (e.g. mywp), so none of your post hyperlinks break. For example:
The /mywp/ will only be in the URL of the posts, not the pages.
5. 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]<!–?php // Silence is golden. ?–>[/php]
If you have any trouble with this process, please visit my Moving WordPress from Subdirectory to Root FAQ.