One of the things that has made WordPress the world's most popular content management system is that it's so easy to set up and use.
There is one problem that people often run into after they set up their WordPress site, though. Their URL is followed by “/wordpress/”, like “www.yoursitename.com/wordpress”. That looks clunky and unprofessional. Imagine if the sites for The New Yorker or Wired had “/wordpress/” in their URL (both of those sites actually are powered by WordPress, by the way). It's just not right.
The root of the problem is that when you installed WordPress, it was saved in the subdirectory called “WordPress” instead of the root directory. But don't worry! This is easy to fix. In this post, I'll show you how.
For Fresh WordPress Installations
Is your site completely new, with no content at all? If so, then you're in luck. All you need to do is go to the cPanel and uninstall the WordPress file stored in the “WordPress” subdirectory. Then, download the WordPress file again and save it in the root directory this time. That's it – easy, right?
For WordPress Sites with Content
If your site already has content, the solution isn't quite as easy, but it's still pretty simple. Let me walk you through it.
After logging in to your WordPress Admin Dashboard, go to “Settings” and click on “General”. Here, you will find two URL options:
- WordPress Address (URL)
- Site Address (URL)
You'll see “/wordpress/” in both URL fields. Remove “/wordpress/” from the “Site Address” field, but keep it in the “WordPress Address” field. Scroll to the bottom of the page and save your changes when you're done.
At this point, if you try to open your site in a browser, you'll be presented with an error telling you that your site doesn't exist. Relax, that's supposed to happen. You should back up your site before you continue, though.
For the next step, you'll need a File Transfer Protocol (FTP) client. Find one, download it, and install it. You'll need to input some information:
- Host: Your site’s URL
- Username: Your cPanel Admin username
- Password: Your cPanel Admin password
Click on the “Quick Connect” button. The “/wordpress/” directory will be displayed on your screen. Download (but don't delete) all the files in this directory to your computer.
Open the index.php file in the text editor. You'll see this code: “require(dirname(_FILE_).’/wp-blog-header.php’)”.
Replace it with: “require(dirname(_FILE_).’/wordpress/wp-blog-header.php’)”.
Finally, upload the updated index.php file and .htaccess file to the root directory. Now your site will be up without “/wordpress/” in the URL.
That previous method is a bit of a workaround. Although it's more complicated, now I'll show you how to move your site directly from the subdirectory to the root folder.
Duplicator Package Creation
First, install the Duplicator plugin. Now go to “Settings” and select “Create New”. This will launch the Duplicator Wizard for creating an installer package of your website.
The plugin will run a few scans, and then you'll need to select “Build” to finish and download the package and installer script.
Fresh WordPress Install and New Database Creation
Go to the cPanel dashboard of your hosting account, scroll down to “databases”, and click on the “MySQL Databases” icon. Choose a name and click on the “Create Database” button. Then, go to the “MySQL users” section, enter in a username and password, and click on the “Create a User” button. Next, go to the “Add User to Database” section and assign the new user to the new database.
Run the Installer
Upload the Duplicator package and installer script to the root directory of your website. Once the upload is complete, open the installer script on a browser. In this browser, you'll have to enter your website’s root URL and add “/installer.php”.
This will open the installer wizard. Use the new database information you created to continue. Duplicator will unpack the WordPress database backup and move it to your new database. To complete the migration, you will have to update the site URL and path, which in most cases is detected automatically.
Final Setup of Subdirectory to Root Folder
You've now successfully moved your site from the subdirectory to the root folder. Congratulations! Now you just need to redirect the new website so that your users can find it when they search for it on a browser.
- Connect to your WordPress site using an FTP client and delete the old /wordpress/ folder.
- Go to the admin area of your WordPress site. After all the above changes, your URL will look like this: https://yoursitename.com/wp-admin
- Install and activate the Redirection plugin.
- Go to “Tools” > “Redirection”.
- This will open the setup wizard. Complete the setup.
- Go to the “redirects” tab and add your new redirect.
- For source URL, you have to add “https://yoursitename.com/wordpress/.*”. For target URL, you have to add “https://yoursitename.com/$1”.
Do you have any questions about this process? Feel free to let me know in the comments section below.