Changing WP installation Directory to Root

It is a common practice to developers to develop a test / development website at folder / directory like http://domainname/wp and later (when the testing process / approval of customer is done) move the website to  root directory to enable it to be visible at http://domainame.

WordPress, however, relies on its URL settings to work correctly. This means that if you simply move your files and database it will not work properly.

Fortunately, wordpress is flexible enough to adjust to above situation. Few methods to undertake above process are mentioned below. These directions are to be used ONLY for single installs of WordPress. If you are using MultiSite install of WP, you will need to manually edit your database.

“It is important to have backup of WP and related files before doing any modification”.

Method-1 Editing functions.php

1. FTP to the site, and get a copy of the active theme's functions.php file. You're going to edit it in a simple text editor and upload it back to the site. Alternatively you can edit the functions.php from within your Cpanel.

2. Add these two lines to the file, immediately after the initial "<?php" line.

update_option('siteurl','http://domainname');
update_option('home','domainname');

Use URL of your website instead of “domainname”.

3. Upload the file back to your site.

4. Load the login or admin page a couple of times. The site should come back up.

Note: After you run your site once and you make sure it works you should delete those lines from your functions.php file. The settings are already stored in your database and should not be modified each time your site is loaded. Do not leave those lines in the functions.php file. Remove them after the site is up and running.

Method -2, Changing WP URL using WP Admin Panel

  1. Login to the admin panel.
  2. Settings > General set your WordPress address to the folder you installed WordPress (without the trailing slash) and set the Blog address to your blog’s root address (without the trailing slash).

    “Worpress address (URL):  http://domainame/wp

Blog address (ULR:  http://domainname

  1. Open the index.php in the WP directory using a text or HTML editor in your cpanle and change the location of your wp-blog-header.php to the new location.

Example: if your WordPress installation folder is ‘WP’,

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

 becomes <?php require('./wp/wp-blog-header.php'); ?>

  1. Upload the edited index.php to your blog’s root directory (i.e. not the ‘WP’ folder) and delete the index.php file from your WordPress directory (i.e. the ‘WP’ folder) or set it to redirect to the root.
  2. If you’re using permalinks or other rewrite rules, the .htaccess file needs to be in the same location as the index.php file (i.e. not the ‘wp’ folder)

Remember that your login and registration links will change. Where you used to visit http://www.domainname/wp-login.php, the location will now be  http://www.domainame/admin/wp-login.php

  1. You will also need to re-generate the permalinks from Settings > Permalinks to make sure they have the new URL. Simply check and save.

Method -3 Changing the Config file

It is also possible to change the website URL manually in the wp-config.php file.

Add these two lines to your wp-config.php, where "domainame" is the correct location of your site.

define('WP_HOME','http://domainname');
define('WP_SITEURL','http://domainanme');

This is not necessarily the best fix, it's just hardcoding the values into the site itself. You won't be able to edit them on the General settings page anymore when using this method.

Method - 4, Redirection instead of Changing URL

You can setup redirect using .htaccess file in the root directory  - the installation will remain in /wp subfolder but your website homepage will be domainname.

Open the .htaccess file in a text editor OR in edit it from within Cpanel.

Add following in the htaccess file root (replacing yourdomain.com with your actual domain name, and wp with your subfolder)

   RewriteEngine On
   RewriteCond %{HTTP_HOST} ^(www\.)?domainname$
   RewriteCond %{REQUEST_URI} !(/|\.[^/]*)$
   RewriteRule (.*) http://www.domainame/$1/ [L,R=301]
   RewriteCond %{HTTP_HOST} ^(www\.)?domainname$
   RewriteCond %{REQUEST_URI} !^/wp/
   RewriteRule ^(.*)$ /wp/$1

 Please understand that this redirect will make /wp disappear only on the homepage, links will still have it - e.g. yourdomain.com/wp/contactus

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How to Speed up Your WP website

WP is one of the resrouces heavy script which needs meassures both at server admin as well as...

About WP Security

WordPress security should not be taken lightly else you keep getting attacks one after the other....

How to Rest WordPress Admin Password Using phpMyAdmin - Cpanel

How to Reset a WordPress Password from phpMyAdmin Resetting WordPress Admin login password is...