Using WordPress Subdirectory and Subdomain

I have mentioned before that there are many methods you can choose during the WordPress installation phase Subdirectory. Of course, it can be installed quickly through Softaculous and similar applications.

When you download from WordPress1 or GitHub2 with wget or curl, you can see that the archive content will be kept in a folder content (wordpress or WordPress-x) unless otherwise specified. For example, let’s say we download the archive. When we unzip the downloaded archive, a folder called wordpress will be created. To edit this situation in a simple way, we can use the command:

unzip -qq && mkdir test && mv ./wordpress/* ./test/ && rm -rf wordpress

The above command transfers the content of the wordpress folder created after the archive to another folder named test and then deletes both the wordpress folder and the archive. If we want the files to be opened directly to the current directory instead of the test in the command, we can update our command as follows:

unzip -qq && mv ./wordpress/* ./ && rm -rf wordpress

For example, let’s download the content of our web address and protect the wordpress folder. In this case, our wordpress installation processes will be published on unless we specify otherwise. Of course, if we define a subdomain, we can publish as In this case, the simplest solution is to move the wordpress content to a parent directory (webroot directly; html, public_html, www, etc.), ie keeping the files in /var/www/html/worpdress under /var/www/html/. However, this is not the only method.

Editing .htaccess

Yes, we can view the WordPress installation in a different folder directly from the main URL by updating the .htaccess file. For this process, we must first move the .htaccess file to the webroot directory. Then we have to edit the file contents as follows.

RewriteEngine on RewriteCond %{HTTP_HOST} ^(www.)?$ RewriteCond %{REQUEST_URI} !^/worpdress/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.\*)$ /wordpress/$1 RewriteCond %{HTTP_HOST} ^(www.)?$ RewriteRule ^(/)?$ wordpress/index.php \[L\]

You can also use this process for web domain name changes. If for some reason you have problems with wp-admin access, you can make the relevant changes by adding the WP_HOME and WP_SITEURL lines to wp-config.php.

define( ‘WP_HOME’, ‘’ );
define( ‘WP_SITEURL’, ‘’ );

With update_option, it is possible to perform the above operation with the functions.php file included in the active theme.

update_option( ‘siteurl’, ‘’ );
update_option( ‘home’, ‘’ );

Another alternative is to use the wp option command via WP-CLI.

wp option update home ‘’
wp option update siteurl ‘’

When you want to make changes to the site address, you can make all changes at once with wp search-replace.

wp search-replace ‘’ ‘’ –skip-columns=guid

Apart from the above operations, there are many alternatives (like SQL commands). For other related alternatives, you can take a look at Changing The Site URL3 and Giving WordPress Its Own Directory4. All these processes are valid for cases where we provide wordpress access via subdirectory and / or directly from the main domain. So, what should we do if we want to use a subdomain? Of course, the same operations for folder arrangements (keeping the wordpress installation in a different folder, etc.) will remain valid. The additional arrangements we need to make are to create a subdomain via cPanel and similar management systems (use of wilcard, of course, I recommend) and edit the .htaccess content as necessary5.

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ – [L]

# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ – [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]

So what do we do when we have your installation in a folder named wordpress but we want to be accessed via

It will be enough to edit the .htaccess content directly in the wordpress folder as follows.

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

The main thing to do is to specify the directory containing the WordPress files as the folder path after determining the subdomain during the creation of the subdomain via cPanel and similar management systems. In other words, we would be viewing our site in the content of /var/www/html/wordpress via the address. Yes, it is possible to manage our WordPress subdirectory and subdomain configurations in different ways within different scenarios.

Subdirectory  Our other content


Latest articles

Related articles