When you cannot access your WordPress site after changing the site URL

Introduction

In general, the WordPress files will be installed under the root directory. But, sometimes they can be installed under sub-directories such as "/wp" or "/wordpress".  In this case, visitors need to include the sub-directory path too in the browser address field to access (for example, by entering "www.abc.com/wp/" or "www.abc.com/wordpress/".) It's not so reasonable. So some beginners tend to change the site URL in the Dashboard by accident.
Site URL and WordPress URL address
You can change the WordPress Address (URL) and the Site Address (URL) under Settings > General.

  • WordPress Address (URL) - The full URL of the directory containing your WordPress core application files (e.g., wp-config.php, wp-admin, wp-content, and wp-includes)
  • Site Address (URL) - The address you want people to type in their browser to reach your WordPress site. This is the directory where WordPress's main index.php file is installed. (Source: WordPress Code - Settings General Screen)

What will happen when you change the WordPress Address and Site URL to the Root directory such as "www.abc.com" while the WordPress files are placed under the sub-directory "/wp"?  As soon as you click "Save Changes" after changing the WordPress Address and Site Address, an error message like the following will appear:

Not Found

The requested URL /wp-login.php was not found on this server.

When you enter your WordPress site address (such as www.abc.com), the following message will be displayed:

Forbidden

You don't have permission to access / on this server.

When you are new to WordPress, you will be at a loss.  You can resolve this problem using the following two methods:

Database Recovery

Many webhosting companies provide the DB Recovery feature as a standard service. Please consult your webhosting company and check they offer such a service. If you can restore your database, you will be able to restore your site easily. If not, you will need to correct the WordPress Address and the Site URL by accessing your Database.

Modify the WordPress Address and the Site URL in the database

Before you follow this method, I recommend you to backup your database. This is done by accessing your Database using the tool named "phyMyAdmin." Please log into your webhosting company site using your account and password, and search a menu such as database. You will find "phpMyAdmin."

phyMyadmin tool

After clicking "phyMyAdmin", please select an appropriate Database name which matches your WordPress site. And then click "wp_options" (or similar) under the left panel.
phpMyAdmin screen_cr
Your screen might be different from the above screen.

  • Click "wp_options" or similar name (1)
  • Click "Browse" (2)
  • Search the option names "siteurl" and "home" (3)

Now you need to modify siteurl and home  option names. You should be careful when changing the database. Please click the Edit icon (a pencil shape) and change the URL address to your original address. Click "Go" to save the changes. Please repeat this changes to both option names "siteurl" and "home". Now you should access your WordPress by entering, for example, "www.abc.com/wp."

Modifying the site url in database
How can we access the WordPress site without entering the sub-directory name?

Changing the WordPress site address to Root from a sub-directory

Let's learn how to setup WordPress to be accessed by entering the Root site address without sub-directory name (e.g. "www.abc.com") while the WordPress files were installed under a sub-directory such as "/wp."

Please change the Site Address (URL) to the root site address by taking the sub-directory name out under Settings > General in the WordPress Dashboard.
Site URL with subdirectory
Now we need to copy the index.php file to the Root directory.  Please copy the index.php file under the WordPress directory in the server to your local computer (under a "temp" directory) using FTP.
copy index to local
Please open the index.php file and modify one line:editing index file in wordpress
Please change the line "require( dirname( __FILE__ ) . '/wp-blog-header.php' );" to add the sub-directoy path. 

require( './wp/wp-blog-header.php' );

(Of course, "wp" should be changed to the sub-directory name where your WordPress files were installed.)

Please upload the modified index.php file to the root directory of your website.

Upload index file in WordPress

All done. Now you should access your site without problems.


Leave a Comment