Home > Help Center > Shared Hosting > Website > How to move a site to a subdirectory?

How to move a site to a subdirectory?

In this article, we'll show you how you can move your site to a subdirectory and keep it working properly without adding the subdirectory name to the page URLs.

In the example the site works from an URL http://bs4.com/ and the files are uploaded to /public_html/bs4.com/ directory, to which the domain bs4.com is configured:

move site subdirectory

We move the files to the /bs4.com/web/ subdirectory:

move site subdirectory

and the site continues to work correctly with the same URL without having to add the name of the subdirectory to the address - ie. http://bs4.com/web/:

move site subdirectory

How is that possible?

Simply, in the /bs4.com/ domain configuration directory, we have put an .htaccess file, which code redirects the requests to the /web/ subdirectory:

move site subdirectory

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^bs4\.com [OR]
RewriteCond %{HTTP_HOST} ^www\.bs4\.com
RewriteCond %{REQUEST_URI} !/web
RewriteRule ^(.*)$ /web/$1 [L]

In the same way, you can change the directory of the main domain in the hosting that is configured by default to load the main site from the public_html directory.

Just create an .htaccess file in public_html and redirect requests to the main domain to any subdirectory. Of course, you should replace the settings in the example with your correct settings.

In the above example, we used a static HTML site.

Let's remove the static site entirely and install WordPress in the same directory /bs4.com/ which will load from the same URL http://bs4.com/.

After installation, the site works normally:

move site subdirectory

We move all the files to the /bs4.com/web/ subdirectory and in the /bs4.com/ directory we create .htaccess file with the contents of the previous example:

move site subdirectory

move site subdirectory

To make sure there is no caching, we'll load the WordPress site from another browser and we create a new article Test Post:

move site subdirectory

In WordPress we are changing the permalinks (Settings > Permalinks) settings by selecting Post name, we save the changes and refresh the browser.

The page should not work because for the correct operation of permalinks there must be an .htaccess file in the WordPress site directory, but we did not create such file during the installation, as you can see from the above image.

Still, the page works correctly and is rewriting the URL address using the slug (test-post) article title:

move site subdirectory

If we open the WordPress site directory, we notice that WordPress automatically created the required .htaccess file when we saved the permalinks change by pressing the Save Changes button:

move site subdirectory


Using .htaccess redirection, it is completely possible to reconfigure static HTML sites. This type of sites are based on HTML/CSS/JS frameworks such as Bootstrap, Foundation, Skeleton, Boilerplate and others.

In the example with the WordPress (wich is a dynamic site) base installation , the site also worked correctly.

Let's add that many or at least some extra plugins are used to run a modern WordPress site, many of which create their own entries in the .htaccess file, and this can cause complications and problems later.

That's why we recommend that when working with dynamic CMS systems, you should follow the developer instructions as closely as possible.

Still not finding what you're looking for?

Contact our support team with any additional questions or concerns.

Contact support