url wordpress_如何从WordPress网站URL摆脱/ wordpress /

url wordpress

Are you trying to remove /wordpress/ from your website’s URL? Sometimes beginners end up installing WordPress in a subdirectory, which causes /wordpress/ to appear in their website URL.

您是否要从网站的网址中删除/ wordpress /? 有时,初学者最终会在子目录中安装WordPress,这会使/ wordpress /出现在其网站URL中。

If you accidentally installed WordPress in a subdirectory and want to move it to the root directory, then you’re in the right place. In this article, we will show you how to get rid of /wordpress/ from your WordPress site’s URL.

如果您不小心将WordPress安装在子目录中,并想将其移动到根目录,那么您来对地方了。 在本文中,我们将向您展示如何从WordPress网站的网址中删除/ wordpress /。

Removing /wordpress/ from your WordPress site url

Note: The method shown in this tutorial works for other subdirectories as well.

注意:本教程中显示的方法也适用于其他子目录。

为什么您在WordPress网站网址中看到/ wordpress / (Why You See /wordpress/ in Your WordPress Site URL)

WordPress is quite easy to install and nowadays most WordPress hosting companies offer quick WordPress installers in thier hosting control panel.

WordPress 易于安装 ,如今,大多数WordPress托管公司都在其托管控制面板中提供了快速的WordPress安装程序。

However, some beginners who are manually installing WordPress may end up accidentally installing it in a subdirectory. Most often this subdirectory is named wordpress.

但是,一些手动安装WordPress的初学者可能最终会意外地将其安装在子目录中。 通常,此子目录名为wordpress。

This happens primarily because users end up uploading the wordpress folder they find inside the official WordPress.org download.

发生这种情况的主要原因是,用户最终上传了他们在WordPress.org官方下载文件中找到的wordpress文件夹。

Let’s take a look at how to easily fix this and get rid of /wordpress/ from your site’s URL.

让我们看一下如何轻松解决此问题,并从网站的网址中删除/ wordpress /。

从WordPress网站网址中删除/ wordpress / (Removing /wordpress/ from WordPress Site URL)

If you have just installed WordPress and there is no content on your website, then you can just go ahead and start over.

如果您刚刚安装了WordPress,但您的网站上没有任何内容,则可以继续并重新开始。

Simply delete the current installation, and follow the instructions in our WordPress installation tutorial to properly reinstall WordPress.

只需删除当前安装,然后按照我们的WordPress安装教程中的说明正确重新安装WordPress。

If you have already added content to your website, then there are two easy ways to remove the /wordpress/ from your site’s URL.

如果您已经向网站添加了内容,则有两种简单的方法可以从网站的网址中删除/ wordpress /。

方法1:更改WordPress网站地址 (Method 1: Change WordPress Site Address)

If you have an established WordPress site, then this method is easier and quicker. The downside of this method is that your media files such as images will still use /wordpress/ in the URL.

如果您已经建立了WordPress网站,那么此方法将更加简便快捷。 这种方法的缺点是您的媒体文件(例如图像)仍将在URL中使用/ wordpress /。

First, you need to login to your WordPress site’s admin area and go to Settings » General page.

首先,您需要登录到WordPress网站的管理区域,然后转到“设置”»“常规”页面。

You will notice the ‘WordPress Address’ and ‘Site Address’ fields and both will have the same URL.

您会注意到“ WordPress地址”和“站点地址”字段,并且两者都有相同的URL。

You need to change the Site Address option and point to your root domain, e.g. http://www.example.com and leave WordPress Address option as it is.

您需要更改“站点地址”选项并指向您的根域,例如http://www.example.com,并保留“ WordPress地址”选项不变。

Once you do that, click on Save Changes button to store your settings.

完成后,单击“保存更改”按钮以存储您的设置。

Change WordPress site address

Next, you need to connect to your website using an FTP client. Once you are connected, go to the /wordpress/ directory and download the .htaccess and index.php files to your computer.

接下来,您需要使用FTP客户端连接到您的网站。 连接后,转到/ wordpress /目录,然后将.htaccess和index.php文件下载到您的计算机。

If you are unable to locate the .htaccess file, then you may need to force your FTP client to show hidden files. If you are using Filezilla, then you need to click on Server from the menu bar and select ‘Force Showing Hidden Files’ option.

如果无法找到.htaccess文件,则可能需要强制FTP客户端显示隐藏文件 。 如果使用Filezilla,则需要从菜单栏中单击“服务器”,然后选择“强制显示隐藏文件”选项。

Show hidden files in your FTP client

Once you have downloaded both files to your Desktop, you need to open index.php file in a text editor like Notepad. In this file you will find a line like this:

将两个文件都下载到桌面后,需要在文本编辑器(如记事本)中打开index.php文件。 在此文件中,您将找到如下一行:

require( dirname( __FILE__ ) . '/wp-blog-header.php' );

This line loads the wp-blog-header.php file which is required to load your WordPress site.

该行加载了wp-blog-header.php文件,这是加载WordPress网站所需的文件。

What you need to do now is enter the correct location of the file by replacing the existing line with this one:

您现在需要做的是通过用以下内容替换现有行来输入文件的正确位置:

require( dirname( __FILE__ ) . '/wordpress/wp-blog-header.php' );

Save your changes and upload both index.php and .htaccess files from your desktop to the root of your domain using FTP. The root folder is the parent folder with the wordpress folder inside it usually called /www/ or /public_html/

保存更改,然后使用FTP将index.php.htaccess文件从您的桌面上载到域的根目录。 根文件夹是父文件夹,其中包含wordpress文件夹,通常称为/ www /或/ public_html /

Root directory with a separate WordPress folder inside it

That’s all. You can now visit your website using the root domain, and everything will work fine. However, if you need to login to your WordPress admin, then you will still need to go to the wp-admin inside the wordpress directory like this:

就这样。 现在,您可以使用根域访问您的网站,并且一切正常。 但是,如果您需要登录到WordPress管理员,则仍然需要转到wordpress目录内的wp-admin,如下所示:

http://www.example.com/wordpress/wp-admin

http://www.example.com/wordpress/wp-admin

方法2:将WordPress移至根目录 (Method 2: Move WordPress to Root Directory)

This method is more comprehensive and will permanently move your WordPress site from the subdirectory to the root folder of your website.

此方法更全面,可将WordPress网站从子目录永久移动到网站的根文件夹。

Step 1. Create a Duplicator Package

步骤1.创建复制程序包

First, you need to install and activate the Duplicator plugin on your website. For more details, see our step by step guide on how to install a WordPress plugin.

首先,您需要在网站上安装并激活Duplicator插件。 有关更多详细信息,请参阅有关如何安装WordPress插件的分步指南。

Upon activation, you need to visit Duplicator » Settings page and click on the ‘Create New’ button.

激活后,您需要访问Duplicator»设置页面,然后单击“新建”按钮。

Create new duplicator package

This will launch the Duplicator wizard, which will create an installer package of your complete website. Click on the next button to continue.

这将启动“复制器”向导,该向导将创建整个网站的安装程序包。 单击下一步按钮继续。

Next, the plugin will run some scans. If everything looks OK, then you can click on the Build button.

接下来,该插件将运行一些扫描。 如果一切正常,则可以单击“生成”按钮。

Build duplicator package

Duplicator will now create a package and prompt you to download it along with the installer script. Go ahead and download both files to your computer.

现在,Duplicator将创建一个程序包,并提示您将其与安装程序脚本一起下载。 继续并将两个文件下载到您的计算机。

Download duplicator package

Step 2. Create a New Database for a Fresh WordPress Install

步骤2.为新的WordPress安装创建新的数据库

You can use the existing WordPress database, but it is better to create a new one so that your old database is safe and unchanged. This way you could revert back to your site without much fuss if something goes wrong.

您可以使用现有的WordPress数据库,但是最好创建一个新的数据库,以便您的旧数据库是安全且不变的。 这样,如果出现问题,您可以轻松地回到站点。

Visit your hosting account’s cPanel dashboard, scroll down to the ‘Databases’ section, and then click on the ‘MySQL Databases’ icon.

访问托管帐户的cPanel仪表板,向下滚动到“数据库”部分,然后单击“ MySQL数据库”图标。

Database cPanel

After that simply provide a name for your database and click on the ‘Create Database’ button.

之后,只需为您的数据库提供一个名称,然后单击“创建数据库”按钮。

Create database

Cpanel will now create a new database for you. After that, you need to scroll down to the ‘MySQL Users’ section.

Cpanel现在将为您创建一个新的数据库。 之后,您需要向下滚动到“ MySQL用户”部分。

From here you need to provide a username and password for your new database user and click on the ‘Create a user’ button.

在这里,您需要为新的数据库用户提供用户名和密码,然后单击“创建用户”按钮。

Create MySQL user

Now you need to assign database permissions to the new user.

现在,您需要为新用户分配数据库权限。

Scroll down to the ‘Add User to Database’ section. Simply select the database user you created from the dropdown menu next to the ‘User’ field, then select the database, and click on the add button.

向下滚动到“将用户添加到数据库”部分。 只需从“用户”字段旁边的下拉菜单中选择您创建的数据库用户,然后选择数据库,然后单击添加按钮。

Add user to database

Your new database is now ready to be used for the fresh WordPress installation.

现在,您的新数据库即可用于全新的WordPress安装。

Step 3. Run the Duplicator Wizard

步骤3.运行复制器向导

Now, you need to upload the Duplicator archive package and the installer file you downloaded earlier to the root directory of your website.

现在,您需要将先前下载的Duplicator存档软件包和安装程序文件上载到网站的根目录。

This will be the directory containing the /wordpress/ folder.

这将是包含/ wordpress /文件夹的目录。

Upload Duplicator files to the root folder of your website

After you have uploaded both files, open the installer script in a browser window. You will need to enter your site’s root URL and then prefix it with /installer.php.

上载两个文件之后,在浏览器窗口中打开安装程序脚本。 您将需要输入站点的根URL,然后以/installer.php为其前缀。

https://example.com/installer.php

https://example.com/installer.php

This will open the Duplicator installer wizard.

这将打开Duplicator安装程序向导。

Duplicator wizard

Check the terms and conditions box and then click on the ‘Next’ button to continue.

选中条款和条件框,然后单击“下一步”按钮继续。

Next, it will ask you to provide the database information. Enter the information for the database we created earlier in step 2.

接下来,它将要求您提供数据库信息。 输入我们先前在步骤2中创建的数据库的信息。

Connect your database

After entering database information, click on the next button to continue.

输入数据库信息后,单击下一步按钮继续。

Duplicator will now unpack your WordPress database backup from the archive into your new database.

现在,Duplicator将把您的WordPress数据库备份从存档中解压缩到新数据库中。

Next, it will ask you to update the site URL and Path. You don’t need to do anything here as it will automatically detect new URL and path. However, if it doesn’t, then you can manually enter it here.

接下来,它将要求您更新站点URL和路径。 您无需在此处做任何事情,因为它会自动检测新的URL和路径。 但是,如果没有,则可以在此处手动输入。

New site settings

Duplicator will now finish the migration, and you will be able to click on the Admin login button to access your website on the new location.

Duplicator现在将完成迁移,您将能够单击Admin登录按钮以在新位置访问您的网站。

Migration finished

Step 4. Set up Subdirectory to Root Folder Redirects

步骤4.将子目录设置为根文件夹重定向

Congrats, you have moved your WordPress site from subdirectory to the root folder.

恭喜,您已将WordPress网站从子目录移动到了根文件夹。

Now it is time to setup redirects, so that your users and search engines can find your website’s new location.

现在是时候设置重定向,以便您的用户和搜索引擎可以找到您网站的新位置。

First, you need to connect to your WordPress site using an FTP client and then delete the old /wordpress/ folder.

首先,您需要使用FTP客户端连接到WordPress网站,然后删除旧的/ wordpress /文件夹。

Delete old wordpress subdirectory

After that, switch to the admin area of your WordPress site. Since you have moved it to the root of your website your WordPress admin URL will be like this:

之后,切换到WordPress网站的管理区域。 由于您已将其移至网站的根目录,因此您的WordPress管理员URL将如下所示:

https://example.com/wp-admin

https://example.com/wp-admin

Now, you need to install and activate the Redirection plugin. For more details, see our step by step guide on how to install a WordPress plugin.

现在,您需要安装并激活重定向插件。 有关更多详细信息,请参阅有关如何安装WordPress插件的分步指南。

Upon activation, you need to visit Tools » Redirection page. The plugin will now show you a setup wizard. Simply click on the continue setup and then finish setup button.

激活后,您需要访问工具»重定向页面。 插件现在将向您显示安装向导。 只需单击继续设置,然后完成设置按钮。

Redirection setup

Next, you need to switch to the ‘Redirects’ tab and add your new redirect.

接下来,您需要切换到“重定向”标签并添加新的重定向。

First check the ‘Regex’ checkbox at the corner of the first field.

首先选中第一个字段一角的“ Regex”复选框。

After that, For source URL you will add https://example.com/wordpress/.* and for Target URL you will add https://example.com/$1.

之后,对于源URL,您将添加https://example.com/wordpress/.* ,对于目标URL,您将添加https://example.com/$1

Redirect subdirectory to root folder

Don’t forget to replace example.com with your own domain name. Click on the ‘Add Redirect’ button to save your changes.

不要忘记用您自己的域名替换example.com。 点击“添加重定向”按钮以保存您的更改。

From now on all users accessing your website with /wordpress/ in the URL will be automatically redirected to correct posts with your new root URL.

从现在开始,所有使用/ wordpress /访问URL的用户将被自动重定向到使用您的新根URL的正确帖子。

That’s all. We hope this article helped you learn how to get rid of /wordpress/ from your WordPress site URL. You may also want to see our comprehensive guide to most common WordPress errors and how to fix them.

就这样。 我们希望本文能帮助您学习如何从WordPress网站网址中删除/ wordpress /。 您可能还想查看有关最常见的WordPress错误以及如何修复它们的综合指南。

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

如果您喜欢这篇文章,请订阅我们的YouTube频道 WordPress视频教程。 您也可以在TwitterFacebook上找到我们。

翻译自: https://www.wpbeginner.com/wp-tutorials/how-to-get-rid-of-wordpress-from-your-wordpress-site-url/

url wordpress

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值