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

[Osaka/Yokohama] 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】サブディレクトリで表示しているサイトをトップページで表示させる方法

*麺Lab 美味身 (大阪吹田)

 

こんにちは!
株式会社ビヨンド大阪オフィスのラーメン王、ヒデです。
今回が11回目の投稿です。

前回はTerraformでセキュリティグループに複数のルールを追加する方法について書きました!
Terraformでセキュリティグループを追加する方法は色々とありますが、併用すると問題が発生することもあります。
その問題の解決策も紹介しているので気になる人はぜひ、確認してみてくださいね。

Terraformでセキュリティグループに複数のルールを追加する方法

 

 

 

概要

『サイトを日本語サイト(/jp)と英語サイト(/en)で表示させていたけど
英語サイト(/en)が必要なくなったから日本語サイトをトップで表示させたいけど.....
これってマジでどうやったらいいの.......』

 

上記のようなことってありませんでしょうか?
初めは二つのサイトをユーザーに表示させていたけど、
必要なくなったのでトップで表示させたいということはあると思います。
そのように設定すること自体は簡単にできますが、
やり方を間違えると画面が真っ白になるなどの不具合が発生してしまいます。
不具合が発生しないように設定ミスが起こりそうなポイントも併せて紹介しますので、一緒に頑張っていきましょう!

 

 

設定方法

*作業前の構成は以下になります。

【設定変更前】
サイト内容 URL ディレクトリパス
なにも表示されない http://localhost/ /var/www/html
日本語サイト http://localhost/jp/ /var/www/html/jp
英語サイト http://localhost/en/ /var/www/html/en

 

 

①Webサイトの動作確認

・http://localhost

 

・http://localhost/jp/

 

・http://localhost/en/

 

 

②バックアップを取得

*作業時の切り戻しのために取得しますので、不具合が発生した場合にお使いください
*不要な方は飛ばしても問題ありません

②-①ディレクトリを移動

cd /var/www/

 

②-②DBをバックアップ

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

*以下ディレクトリに.my.cnfを作成しておくとパスワードなしでバックアップできます

cat /root/.my.cnf

[client]
user=root
password='{password}'

 

②-③コンテンツをバックアップ

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

 

 

③「index.php」と「.htaccess」のコピー

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

 

 

④「index.php」の編集

*コピー先のファイルを編集してください

vi /var/www/html/index.php

*編集前

<?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/】に編集

*編集後

<?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';

 

 

⑤「.htaccess」の編集

*コピー先のファイルを編集してください
*この時点でルートディレクトリとサブディレクトリ両方でサイトが表示できるようになります

vi /var/www/html/.htaccess

*編集前

<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] ←ここを[/index.php】に編集します
</IfModule>

*編集後

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

 

 

⑥サイトアドレス(URL)の変更

*二通り紹介しますので、お好きな方法をお使いください

管理画面から変更する場合
*必ずサイトアドレス(URL)にある(/jp)を消して保存してください
*WordPressアドレス(URL)を変更すると管理画面にアクセスすることができなくなります

 


wordpress設定ファイルから変更する場合
*WP_HOMEがサイトアドレス(URL)に対応する設定になりますので、必ずこちらを指定してください
*WP_SITEURLはWordPressアドレス(URL)に対応しますので、指定すると管理画面にアクセスできず、画面が真っ白になるなど不具合が発生しますので注意してください

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

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

 

 

⑦Webサイトの動作確認

*作業後の構成は以下になります。

【設定変更後】
サイト内容 URL ディレクトリパス
日本語サイト http://localhost/ /var/www/html
なにも表示されない http://localhost/jp/ /var/www/html/jp
英語サイト http://localhost/en/ /var/www/html/en

・http://localhost

 

・http://localhost/jp/

 

・http://localhost/en/
*英語サイトは表示されますが使用しない場合は、削除するか公開ディレクトリから移動するようにしてください

まとめ

どうでしたでしょうか?
サブディレクトリで表示されているサイトをトップページに簡単に表示できたと思いますが、
設定項目を間違えると管理画面にアクセスできなくなったり、サイトが真っ白になるなど不具合が発生することがわかったと思います。
ミスが起こりそうなポイントをしっかり抑えて設定すると問題は起こらないので、しっかり確認して設定をしてくださいね!
それでは、ご覧頂きありがとうございました!

この記事がお役に立てば【 いいね 】のご協力をお願いいたします!
2
読み込み中...
2 票, 平均: 1.00 / 12
2,619
X facebook はてなブックマーク pocket
[2024.6.30 CentOS support ended] CentOS server migration solution

[2024.6.30 CentOS support ended] CentOS server migration solution

[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

[Osaka/Yokohama] Actively recruiting infrastructure engineers and server side engineers!

[Osaka/Yokohama] Actively recruiting infrastructure engineers and server side engineers!

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