How to Install WordPress in a Separate Directory

There may arise a need to install WordPress in a Separate Directory on the server. This is a good idea when you have to manage multiple websites in one hosting space.

If you have searched and landed on the following site – https://wordpress.org/support/article/giving-wordpress-its-own-directory/, you are at the right place. But this is not something quite easy to understand unless you are an expert in PHP and Webserver semantics.

Let us understand, Why it is a good idea?

Some benefits of Installing WordPress Root Site in its Own Directory –

  • Keeps your root directory clutter-free
  • Easy to maintain and debug in case you are hosting multiple sites from one hosting plan
  • Helps tighten the security at the root level

How to do it?

Follow the below given simple steps and you should be ready with your setup in no time.

Go to the file manager -> public_html folder from the hosting cPanel login and make changes in the following files. Make sure to move all the content inside a directory_of_your_choice.

Changes required in .htaccess file

# BEGIN
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.<<your_website_domain>>/$1 [R,L]
# EXAMPLE RewriteRule ^(.*)$ https://www.your_domain.com/$1 [R,L]

Changes required in index.php file

<?php
/**
 * Front to the WordPress application. This file doesn't do anything, but loads
 * wp-blog-header.php which does and tells WordPress to load the theme.
 *
 * @package WordPress
 */

/**
 * Tells WordPress to load the WordPress theme and output it.
 *
 * @var bool
 */
define( 'WP_USE_THEMES', true );

/** Loads the WordPress Environment and Template */
require( dirname( __FILE__ ) . '/<<directory_of_your_choice>>/wp-blog-header.php' );

That’s it! Done. You can browse your WordPress root site through the domain name now. It will be routing your request via the index.php with the help of .htaccess file situated at the root (public_html) folder.

Further Readings

Feel free to drop in comments with your queries in case you get stuck while performing these steps. We will definitely try to help you out. 🙂

Spread the word!
0Shares

Leave a comment

Your email address will not be published. Required fields are marked *

One thought on “How to Install WordPress in a Separate Directory”