top of page

Posts

How to display a site that is currently shown in a subdirectory on the top page in WordPress

Overview


"I had my site set up to display in Japanese (/jp) and English (/en), but since I don't need the English site (/en) anymore, I want the Japanese site to be displayed at the top... How  can I do this?"


Is something like the above happening? It's conceivable that you initially displayed two sites to users but now want to display only one at the top because it's no longer needed. While setting it up like this is relatively simple, making a mistake in the process could lead to issues such as the screen going completely blank. I'll also introduce points to watch out for to prevent such issues, so let's work on it together to avoid configuration errors and ensure everything runs smoothly!


Configuration


*The configuration before the operation is as follows.


【Before the change of setting】


Site Contents

URL

Directory path

Nothing is displayed

/var/www/html

Japanese website

/var/www/html/jp

English website

/var/www/html/en


①confirmation of website operation










②Obtain backup


As rollback can be obtained during work, it will be helpful if any issue occurs.

And it is okay to skip if not needed.


②-① Move the directory


cd /var/www/


②-② Backup the database


mysqldump -u root --single-transaction {database} > {database}_$(date +"%Y%m%d").sql


If you create the .my.cnf file in the following directory, you can perform backups without a password required.


cat /root/.my.cnf

 

[client]

user=root

password='{password}'


②-③ Backup the content


tar -czvf html_$(date +"%Y%m%d").tar.gz html/


Copy of 'index.php' and '.htaccess'


cp -ip /var/www/html/jp/index.php /var/www/html/

cp -ip /var/www/html/jp/.htaccess /var/www/html/


Editing 'index.php'


* Edit the destination file

vi /var/www/html/index.php

*Before editing

<?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-blog-header.php'; ←Edit this part to [/jp/]


* After editing

<?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 . '/jp/wp-blog-header.php';


Editing '.htaccess'


* Edit the destination file

* At this point, the website will be viewable in both the root directory and the subdirectory.


vi /var/www/html/.htaccess


*Before editing

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

RewriteBase /jp/ ←ここを【/】に編集

RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /jp/index.php [L] ←Change this part to [/index.php]

</IfModule>


* After editing

<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>


⑥ Change the website address (URL)


* I will introduce two methods, so please use whichever you prefer.


If you are changing it from the management panel:

  • Be sure to remove '/jp' from the site address (URL) and save it.

  • Changing the WordPress address (URL) will make it impossible to access the management panel.




If you are changing it from the WordPress settings file:

  • WP_HOME corresponds to the site address (URL), so be sure to specify it.

  • WP_SITEURL corresponds to the WordPress address (URL). Specifying it will result in an inability to access the management panel and may cause issues such as a blank screen, so please be cautious.


vi /var/www/html/jp/wp-config.php

define( 'WP_HOME', 'https://{domain}' );


⑦  Check the website content


The configuration after the operation will be as follows:


【After the change of setting】

Site Contents

URL

Directory path

Japanese website

/var/www/html

Nothing is displayed

/var/www/html/jp

English website

/var/www/html/en






   


 If the English website is displayed but not used, please delete it or move it out from the public directory.


Summary


I believe you were able to easily display the site that was previously shown in the subdirectory on the homepage. 


However, if you make a mistake in the settings, issues such as being unable to access the management panel or the site appearing blank can occur. 

By firmly grasping the points where mistakes are likely to occur and setting them carefully, you can avoid problems. 

So, please make sure to check and set the configurations properly! 


Thank you for reading!


This blog post is translated from a blog post written by Tokuhara on our Japanese website Beyond Co..

Recent Posts

See All

Komentar


bottom of page