[WordPress] 如何将子目录中的网站显示在首页

*Men Lab Umi(大阪府吹田市)

 

大家好!
我是来自Beyond Inc.大阪办公室的拉面大王Hide。
这是我的第11篇帖子。

上次我写了如何使用 Terraform 向安全组添加多条规则!
使用 Terraform 添加安全组的方法有很多种,但组合使用有时会导致问题。
我还介绍了一种解决该问题的方法,如果您感兴趣,请务必查看。

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

 

 

 

概述

“我之前的网站同时显示日语(/jp)和英语(/en)版本,但我
现在不再需要英语(/en)版本了,所以我想让日语版本显示在最上方……
我该怎么做呢……?”

 

你是否遇到过类似上述的情况?你可能
最初向用户展示了两个网站,但后来
意识到不再需要它们,只想在顶部显示一个。
这样设置很简单,但
如果操作不当,可能会遇到诸如空白屏幕之类的问题。
我们还会介绍一些你可能在设置中犯错的地方,以避免出现问题,让我们一起来看看吧!

 

 

如何设置

工作前的配置如下:

[更改设置前]
网站内容 网址 目录路径
未显示任何内容 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/

 

 

②获取备份

*此信息用于恢复工作,如有问题请使用。
*如不需要,可跳过。

②-① 移动目录

cd /var/www/

 

②-②备份数据库

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_$(日期+"%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}' );

 

 

⑦检查网站运行情况

工作完成后的配置如下:

[更改设置后]
网站内容 网址 目录路径
日文网站 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
3,968
X Facebook 哈特纳书签 口袋

写这篇文章的人

关于作者

隐藏@基础设施工程师

这一切都始于一次非常有趣的采访。
大阪系统解决方案部门的一名职业中期员工。我的
工作是构建和运营服务器和云!
我拥有 LPIC1、AWS SAA 和 OCI 架构师助理资格。

其实我很喜欢拉面,
已经调查过大阪100多家店了(。-∀-)我要努力成为Nibi Beyond

我也在Twitter,所以请关注我(´∇`)
点击右上角的Twitter标记! !