There are many different situations that can arise where it makes sense to install WordPress into a subdirectory. They may vary from the need to set up a temporary installation for development purposes or just simply because you want to keep your root directory clutter free. No matter what you’re reasoning or situation is the fact that WordPress allows you to install it into a subdirectory is great. When the time comes that you want to have your subdirectory installation served from the website root, there are a couple of ways to achieve this. In this tutorial we will teach you how to serve your WordPress subdirectory installation from the website root without having to move any files.

Step 1: Creating your Root Directory index.php Redirect

In the first step of this tutorial we will need to create a redirect for your WordPress subdirectory in order to serve it from the website root. Open the index.php file that is found on your server’s root directory or create one if it does not already exist. Copy and paste the PHP code below into your index.php file, make sure to change where it says ‘YOUR-SUBDIRECTORY’ to your WordPress installation’s specific subdirectory name, then upload your index.php file to the server’s root directory.

PHP

<?php
define('WP_USE_THEMES', true);
require('./YOUR-SUBDIRECTORY/wp-blog-header.php');
?>

Step 2: Editing the Site Address (URL) in the WordPress Dashboard

In step 2 of this tutorial we will need to edit the Site Address (URL) in the WordPress Dashboard by following the steps below:

  1. Log in to the dashboard of your WordPress site
  2. Go to Settings -> General
  3. Change the Site Address (URL) to the root

Change the Site Address (URL) to the root

Step 3: Modify the .htaccess File (*if necessary)

In step 3 of this tutorial we will need to modify the .htaccess file to rewrite it to your WordPress installation’s subdirectory if it has not already been automatically updated after Step 2. Open the .htaccess file that is found on your server’s root directory or create one if it does not already exist. Copy and paste the code below into your .htaccess file, make sure to change where it says ‘YOUR-SUBDIRECTORY’ to your WordPress installation’s specific subdirectory name, then upload your .htaccess file to the server’s root directory.

htaccess

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . YOUR-SUBDIRECTORY/index.php [L]
</IfModule>

Troubleshooting

If you are having problems getting this tutorial to work please reread the tutorial and try again, if you still cannot get it to work please leave us a comment below and we will respond as soon as possible. Please do not email us with problems regarding this tutorial, only comments will be responded to.

Share This