[Osaka/Yokohama/Tokushima] Looking for infrastructure/server side engineers!

[Osaka/Yokohama/Tokushima] Looking for infrastructure/server side engineers!

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Successor to CentOS] AlmaLinux OS server construction/migration service

[Successor to CentOS] AlmaLinux OS server construction/migration service

[For WordPress only] Cloud server “Web Speed”

[For WordPress only] Cloud server “Web Speed”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Reservation system development] EDISONE customization development service

[Reservation system development] EDISONE customization development service

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[Global exclusive service] Beyond's MSP in North America and China

[Global exclusive service] Beyond's MSP in North America and China

[YouTube] Beyond official channel “Biyomaru Channel”

[YouTube] Beyond official channel “Biyomaru Channel”

[WordPress] How to display a site displayed in a subdirectory on the top page

*Noodle Lab Mimi (Suita, Osaka)

 

Hello!
My name is Hide, the ramen king of Beyond Osaka Office.
This is my 11th post.

Last time, I wrote about how to add multiple rules to a security group in Terraform!
There are various ways to add security groups in Terraform, but problems may occur when using them together.
We have also introduced a solution to this problem, so if you are interested, please check it out.

https://beyondjapan.com/blog/2022/10/terraform-how-to-use-security-group/

 

 

 

overview

I was displaying the site as a Japanese site (/jp) and an English site (/en), but I
no longer need the English site (/en), so I would like to display the Japanese site at the top...but
this Seriously, what should I do...'

 

Have you ever experienced anything like the above?
You may have initially displayed two sites to the user, but now you
no longer need them and would like to display them at the top.
Setting it up like this is easy, but
if you do it incorrectly, problems such as a blank screen may occur.
We will also introduce points where setting mistakes are likely to occur in order to avoid problems, so let's do our best together!

 

 

Setting method

*The configuration before work is as follows.

[Before setting change]
Site content URL directory path
nothing is displayed http://localhost/ /var/www/html
Japanese site http://localhost/jp/ /var/www/html/jp
English site http://localhost/en/ /var/www/html/en

 

 

① Website operation check

・http://localhost

 

・http://localhost/jp/

 

・http://localhost/en/

 

 

② Get a backup

*This information is obtained for switching back during work, so please use it if a problem occurs.
*If you do not need it, there is no problem in skipping it.

②-① Move directory

cd /var/www/

 

②-② Back up DB

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

*If you create .my.cnf in the following directory, you can back up without a password.

cat /root/.my.cnf [client] user=root password='{password}'

 

②-③ Back up content

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

 

 

③ Copy “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/

 

 

④ Edit “index.php”

*Please edit the copy 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'; ←ここを【/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';

 

 

⑤ Edit “.htaccess”

*Please edit the copy destination file
*At this point, you will be able to view the site in both the root directory and subdirectories.

vi /var/www/html/.htaccess

*Before editing

<IfModule mod_rewrite.c>RewriteEngine On RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteBase /jp/ ←Edit this to [/] RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /jp/index.php [L] ←Edit this 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 of site address (URL)

*We will introduce two methods, so please use the method you prefer.

When changing from the admin screen
*Be sure to delete (/jp) from the site address (URL) before saving.
*If you change the WordPress address (URL), you will not be able to access the admin screen.

 


When changing from the wordpress configuration file
*WP_HOME corresponds to the site address (URL), so be sure to specify this
*WP_SITEURL corresponds to the WordPress address (URL), so if you specify it, the admin screen will be displayed. Please note that you may not be able to access it and may experience problems such as a blank screen.

vi /var/www/html/jp/wp-config.php define( 'WP_HOME', 'https://{domain}' );

 

 

⑦ Website operation check

*The configuration after work is as follows.

[After setting change]
Site content URL directory path
Japanese site http://localhost/ /var/www/html
nothing is displayed http://localhost/jp/ /var/www/html/jp
English site http://localhost/en/ /var/www/html/en

・http://localhost

 

・http://localhost/jp/

 

・http://localhost/en/
*The English site will be displayed, but if you do not use it, please delete it or move it from the public directory.

summary

How was it?
I think you were able to easily display the site displayed in the subdirectory on the top page, but I think
you have learned that if you make a mistake in the settings, problems such as not being able to access the management screen or the site turning white can occur. .
If you carefully check the points where mistakes are likely to occur, you will avoid any problems, so be sure to check carefully before setting!
Well then, thank you for watching!

If you found this article helpful , please give it a like!
2
Loading...
2 votes, average: 1.00 / 12
3,033
X facebook Hatena Bookmark pocket
[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

The person who wrote this article

About the author

Hide@Infrastructure Engineer

It all started with a very interesting interview.
A mid-career employee of the System Solutions Department in Osaka.My
job is to build and operate servers and clouds!
I have the qualifications of LPIC1, AWS SAA, and OCI Architect Associate.

Actually, I love ramen and
have investigated over 100 stores in Osaka (。-∀-) I'm striving to become the Ramen King of Nibi Beyond
!

I'm also on Twitter, so please follow me (´∇`)
Click on the Twitter mark on the right corner! !