Moving a website from a subfolder to the main domain
Sometimes a website is built in a subfolder, so it opens at an address like example.com/new or example.com/wp. When it’s ready, you’ll want it to open at example.com instead. In these steps, replace example.com with your own domain and new with your folder’s name.
Before you start
Section titled “Before you start”Make a backup of your files and database. If anything goes wrong, you can put everything back.
Step 1: Clear out the main folder
Section titled “Step 1: Clear out the main folder”Your main domain loads from the public_html folder.
- In cPanel, open File Manager and go to
public_html. - Turn on Show Hidden Files in Settings (top right), so you can see files such as
.htaccess. - Move any old files you no longer need out of
public_html, for example into a new folder calledold-site. Leave your subfolder (new) where it is.
Step 2: Move the files up
Section titled “Step 2: Move the files up”- Open your subfolder (
public_html/new). - Click Select All, then Move.
- Change the destination to
/public_htmland click Move Files. - Check that
index.phporindex.htmlis now directly insidepublic_html.
Step 3: Update your site’s address
Section titled “Step 3: Update your site’s address”WordPress:
- Log in to phpMyAdmin, open your site’s database and the
wp_optionstable (thewp_prefix may differ). - Change
siteurlandhomefromhttps://example.com/newtohttps://example.com. - Log in to WordPress and update links inside your content with a search-and-replace plugin, replacing
example.com/newwithexample.com. - Go to Settings → Permalinks and click Save Changes. This rebuilds your
.htaccessrules.
Other applications: update the site URL in your app’s settings or configuration file, then check .htaccess for any RewriteBase /new/ line and change it to RewriteBase /.
Step 4: Clear the cache and test
Section titled “Step 4: Clear the cache and test”Ruachost servers run LiteSpeed, so pages may be cached. If you use the LiteSpeed Cache plugin, click Purge All, then clear your browser cache. Open example.com and click through a few pages, forms and images.
When everything works, you can delete the empty subfolder and the old-site folder.