WordPress

How to Hide WordPress Installation Directory from Public URL

This time, I will explain in detail how to hide the WordPress installation directory (/wp/) from public URLs. Normally, if WordPress is installed in the /wp/ directory on the server, that directory will appear in the URL. For example:

  • Example of public URL: https://xxxxxx.com/wp/
  • Example of admin panel URL: https://xxxxxx.com/wp/wp-login.php

In this state, “/wp/” will be visible when users access your site. This guide explains how to keep the admin panel URL unchanged while removing “/wp/” from public URLs, as shown below:

  • Example of public URL: https://xxxxxx.com/

With this configuration, the directory where WordPress is installed will be hidden, and the URL will appear cleaner.

Upload WordPress Files to Installation Directory (/wp/) on Web Server

First, download WordPress files from the official website (https://wordpress.org/) and upload them to the /wp/ directory on your web server. This ensures all WordPress files are correctly placed on the server.

Directory structure after upload:

Website Root Directory
│
└──wp
    │  index.php
    │  license.txt
    │  readme.html
    │  wp-activate.php
    │  wp-blog-header.php
    │  wp-comments-post.php
    │  wp-config-sample.php
    │  wp-cron.php
    │  wp-links-opml.php
    │  wp-load.php
    │  wp-login.php
    │  wp-mail.php
    │  wp-settings.php
    │  wp-signup.php
    │  wp-trackback.php
    │  xmlrpc.php
    │
    ├─wp-admin
    ├─wp-content
    └─wp-includes

With this directory structure, proceed to the next steps.

Upload “.htaccess” File to Installation Directory (/wp/)

Next, upload a specific “.htaccess” file to the /wp/ directory where WordPress is installed. Below is the content of the file:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /wp/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wp/index.php [L]
</IfModule>
# END WordPress

This file enables WordPress’s URL rewrite functionality to prevent the installation directory “/wp/” from appearing in public URLs.

Upload “index.php” and “.htaccess” Files to Root Directory

Next, upload the “index.php” file and “.htaccess” file to the root directory of the website (/). This removes “/wp/” from public URLs.

Content of “index.php” File

Below is the content of the “index.php” file to upload to the root directory:

<?php
/**
 * Front to the WordPress application. This file doesn't do anything, but loads
 * wp-blog-header.php which does and tells WordPress to load the theme.
 *
 * @package WordPress
 */

/**
 * Tells WordPress to load the WordPress theme and output it.
 *
 * @var bool
 */
define( 'WP_USE_THEMES', true );

/** Loads the WordPress Environment and Template */
require __DIR__ . '/wp/wp-blog-header.php';

Content of “.htaccess” File

The content of the “.htaccess” file to upload to the root directory is as follows:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

By properly placing these files, the WordPress installation directory can be hidden from public URLs.

Directory Structure After Upload

Below is an example of the directory structure after placing the “index.php” and “.htaccess” files in the root directory:

Website Root Directory
│
│  index.php ← Uploaded here
│  .htaccess ← Uploaded here
│
└──wp
    │  .htaccess
    │  index.php
    │  license.txt
    │  readme.html
    │  wp-activate.php
    │  wp-blog-header.php
    │  wp-comments-post.php
    │  wp-config-sample.php
    │  wp-cron.php
    │  wp-links-opml.php
    │  wp-load.php
    │  wp-login.php
    │  wp-mail.php
    │  wp-settings.php
    │  wp-signup.php
    │  wp-trackback.php
    │  xmlrpc.php
    │
    ├─wp-admin
    ├─wp-content
    └─wp-includes

Prepare Database and Install WordPress

With the WordPress files correctly set up on the server, prepare the database (hostname, username, password) and access the following URL to install WordPress:

  • Admin panel URL: https://xxxxxx.com/wp/wp-login.php

After installation, log in to the WordPress admin panel and navigate to “Settings” → “General” to configure the URLs as follows:

  • WordPress Address (URL): https://xxxxxx.com/wp
  • Site Address (URL): https://xxxxxx.com

Conclusion

By using the method described here, it is possible to hide the WordPress installation directory from public URLs even if WordPress is installed in the “/wp/” directory. This configuration provides cleaner, simpler URLs, enhancing the user experience. Additionally, it may offer slight improvements in site security, so feel free to use this setup.

Note: Please use this guide at your own risk.