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:
- It keeps your root directory clean and tidy (in case you need to add any other PHP applications to your site).
- 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.
- 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, YOU MUST DO THE FOLLOWING. DO NOT READ FURTHER UNTIL YOU HAVE READ THESE THINGS:
a) Clear ALL pages cached by your caching plugin cache AND then de-activate the caching plugin. Also, de-activate Broken Link Checker and any Redirection plugins;
b) Remove any old site files from the root directory — perhaps copy them to a folder called _backup – this includes an index.html file which will totally make this process not work. You MUST remove all those old site files and folders or move them into another directory, so they don’t interfere with WordPress. Having an index.html and index.php in the same folder causes confusion, and likely, the index.html will be used instead of WordPress’ index.php file;
c) Make 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) Use wp-db-backup to make a backup of your database – http://wordpress.org/plugins/wp-db-backup/;
e) Be sure you have 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:
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.
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.
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, e.g. from http://www.yoursite.com/mywp/post-title/ to http://www.yoursite.compost-title/ 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.
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]<!–?php // Silence is golden. ?–>[/php]
A Note About Using Cforms if 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.
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.
If this process was successful, please comment with a thumbs UP below, share on Twitter, follow me on Facebook. Thanks!!!