X

How to Install WordPress in a Separate Directory

A WordPress installation contains a lot of files and can clutter up your website’s root directory. This is especially painful if you are using shared hosting and you would like to keep the root directory of your primary domain clean. This guide shows you how to install WordPress in a separate directory instead of installing in the root directory.

  1. Install WordPress in a separate folder. i.e. If your website root is https://techzog.com/ then install WordPress in https://techzog.com/wp. Your website (WordPress installation) can now be accessed at https://techzog.com/wp
  2. Log in to your WordPress install https://techzog.com/wp/wp-admin.
  3. Go to the General panel.
  4. In the box for Site address (URL): change the address to the root directory’s URL. Example: https://techzog.com
  5. Click Save Changes. At this point, your website will not be accessible.
  6. Copy (NOT MOVE!) the index.php and .htaccess files from the WordPress (https://techzog.com/wp in our example) directory into the root directory of your site—the latter is probably named something like www or public_html.
  7. If you have an old site or have configured permalinks in this WordPress installation then again Copy (NOT MOVE!) the .htaccess file from the WordPress directory into the root directory of your site. The .htaccess file is invisible, so you may have to set your FTP client to show hidden files. If you are running WordPress on a Windows (IIS) server and are using pretty permalinks, you’ll have a web.config rather than a .htaccess file in your WordPress directory.
  8. Edit your root directory’s index.php. Open your root directory’s index.php file in a text editor and change the line that says:
    require( dirname( __FILE__ ) . '/wp-blog-header.php' );

    to the following, using your directory name for the WordPress core files:

    require( dirname( __FILE__ ) . '/wordpress/wp-blog-header.php' );
  9. Save the file.
  10. Login to your site (if you aren’t still already). The URL should still be https://techzog.com/wp/wp-admin/
  11. If you have set up Permalinks, go to the Permalinks panel and update your Permalink structure. WordPress will automatically update your .htaccess file if it has the appropriate file permissions. If WordPress can’t write to your .htaccess file, it will display the new rewrite rules to you, which you should manually copy into your .htaccess file (in the same directory as the main index.php file.)

Note: Since the site will be down during some of these steps, it is best to make this change at a time of low activity, e.g., the middle of the night.

Source: https://codex.wordpress.org/Giving_WordPress_Its_Own_Directory

You might also want to read up on How to Redirect 404 pages in WordPress and How to add a Back Button in your WordPress page.

Comment Policy: Comments adding value to the article are encouraged. Relevant links will be allowed in such comments.
If you think that you have a link that adds value to this article please contact us at techie[at]techzog[dot]com for evaluation of inclusion into the article.
Comments left solely for spamming links will be deleted. Thank you for understanding.
Varun: Passionate blogger and main author at Techzog.com. Feel free to reach me at techie[at]techzog[dot]com
Related Post