Installing WordPress in a different directory: Displaying WordPress in a different directory
Many people want WordPress to power their website’s root (e.g. http://example.com) but they don’t want all of the WordPress files cluttering up their root directory. WordPress allows you to install it into a subdirectory, but have your website served from the website root.
WordPress is most often installed in the directory you wish to run the site in. For example:
example.com
example.com/digital_marketing
In these examples, the URL you are visiting will load the WordPress site that's installed in that directory.
Wordpress has the option to install in a different directory, but have it display from another directory.
This post explains how to display WordPress from either the root directory or subdirectory when it's been installed somewhere else.
Displaying WordPress in a subdirectory if it's installed in the root directory
Let’s say you’ve installed wordpress at example.com. But now you want to display wordpress at example.com/digital_marketing.
1.Log into your site via FTP or SSH.
2.Navigate into your website's directory. Make sure to change username
3.Create the subdirectory (This example creates a subdirectory named digital_marketing)
4.Move all of the files in the root directory (example.com) into the subdirectory example.com/digital_marketing).
5.Create an .htaccess file via FTP or SSH in the root directory (example.com). Add the following contents to the file.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/digital_marketing/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /digital_marketing/$1
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ digital_marketing/index.php [L]
</IfModule>
Note: You only need to update the highlighted text which is your domain name and the subdirectory you created.
Now, when you visit example.com/digital_marketing, you will see your WordPress site.
Displaying WordPress in the root directory if it's installed in a subdirectory
Now I will talk about the opposite steps at the above steps. When you've installed WordPress in a subdirectory at example.com/digital_marketing, but you want it to display when visiting example.com.
Note: These steps only allow you to view your WordPress site at example.com. When you login into the admin dashboard you must visit example.com/digital_marketing/wp-login.php. This is because the original installation was installed into example.com/digital_marketing, so all URLs in the database still point to the /digital_marketing subdirectory.
1.Log into your site via FTP or SSH.
2.Navigate into your website's subdirectory. Make sure to change the username to your Shell user.
3. Copy the index.php and .htaccess files into the root directory.
4. Navigate into your root directory.
5.Edit the index.php file via FTP or SSH. Add the subdirectory name just before /wp-digital_marketing-header.php. For example:
/** Loads the WordPress Environment and Template */
require __DIR__ . '/digital_marketing/wp-blog-header.php';
Note: You only need to update the highlighted text.
6.If you have already configured permalinks, navigate to the Settings > Permalinks page and re-save them.
Now, if you visit example.com, you will see the wordpress site.
We hope this post helped you to understand the difference between root directory and subdirectory.
0 Comments
Thanks for Comment