How to move WordPress to another directory

How To Move Wordpress To Another Directory

How to Change WordPress Directory or Location and Configure It

It is advisable to install the blog and all WordPress files in a dedicated directory from the start. This prevents cluttering the root directory and avoids mixing everything up if additional items are added to the server space later on.

However, the blog can also be launched from the root directory with just the domain name in .fr, .com, .info, etc. For example, by typing in your browser: http://www.example.com.

If this configuration wasn’t done initially, WordPress can still be moved to its own directory by following these steps:

Steps to Follow:

  1. Create the new location where the WordPress core files will be stored using Filezilla, for example (in this example, the directory name used is /myblog).
  2. Go to the configuration panel, Settings, and General.
  3. In the WordPress Address field, replace the existing address with the new location of your WordPress core files. Example: http://example.com/myblog
  4. In the Site Address field, replace the existing address with the URL of your root directory. Example: http://example.com
  5. Click on Save Changes.
  6. Move the WordPress core files to the new location (in this case /myblog), again using Filezilla.
  7. Copy the index.php and .htaccess files to the root of your site. (example.com).
  8. Open the index.php file located in the root directory with a text editor (right-click and edit).
  9. Make the following changes. Change the line:
  10. require('./wp-blog-header.php');

    to the following line, using the directory name of your WordPress core files:

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

    then save the file.

  11. Log in to administer your blog from the new location. This should now be http://example.com/myblog/wp-admin.
  12. If permalinks were configured, go to the Permalinks Settings panel and update the permalink structure.

Note: By default, WordPress uses web addresses containing a question mark and a string of numbers. However, WordPress offers the possibility to create a custom address structure for permalinks and archives. This can improve the aesthetics, usability, and longevity of the links.

It is recommended to use a custom permalink structure, which is appreciated by both Google and readers! A suggested structure is: /%day%/%monthnum%/%year%/%postname%/, as it displays the date in European format and the article title in plain text. WordPress will automatically update the .htaccess file.

If WordPress was installed in a directory from the start, begin only from step 3.

The .htaccess File

The .htaccess files are customizable configuration files for your host (for Apache servers).

They can be used to modify access rights, create redirects, and write custom error messages.

They can be placed in any directory of the blog or hosting space, and the configuration will then apply to the directory and all directories it contains.

To create a .htaccess file, create a new file using a text editor (Notepad, for example) on your PC and save it as htaccess.txt.

Then, once created, transfer the file with Filezilla and rename it on the server to .htaccess, as Windows does not allow saving files as .htaccess.

Here are the lines that make up the .htaccess file: (myblog being, of course, the example of the installation directory)

# BEGIN WordPress

RewriteEngine On
RewriteBase /myblog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /myblog/index.php [L]

AddType x-mapp-php5 .php
DirectoryIndex index.php/

# END WordPress

Note: the line AddType x-mapp-php5 .php is specific to 1&1, it forces the use of the PHP v5 engine.