将 Wordpress 站点 URL 从子域更改为子目录 [英] Changing Wordpress Site URL from Subdomain to Sub Directory

查看:49
本文介绍了将 Wordpress 站点 URL 从子域更改为子目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是 911;我需要将我创建 GoDaddy WP 安装的 Wordpress 子域 URL 更改为子目录 URL.我不能在我的 FTP 根站点文件夹中创建一个文件夹并传输 WP 文件吗?没有迁移插件工作.

This is a 911; I need to change a Wordpress subdomain URL that I created a GoDaddy WP installation to a subdirectory URL. Can't I just make a folder in my FTP root site folder and transfer the WP files over? No migration plugins work.

我知道我应该在 GoDaddy 上安装 WP 到正确的根目录,但我不认为修复会如此困难.

I know that I should've installed the WP on GoDaddy on the proper root directory, to begin with, but I didn't think it would be this difficult to fix.

我很清楚我希望 example.myrooturl.com 成为 myrooturl.com/example.如果可能的话,我需要最直接、最快捷的方法来做到这一点

Just so I'm clear I want example.myrooturl.com to be myrooturl.com/example. I need the most straight forward, quickest way to do this if possible

推荐答案

我不得不经常做与您要求相反的事情.移动 Wordpress 站点可能会很棘手,因为站点的规范 URL 存储在数据库中,并且许多内部链接也与完整 URL(不是相对的)一起存储.根据我的经验,这可以通过几个步骤在 5 分钟内完成,但要为几分钟的停机时间做好准备:

I have had to do the reverse of what you're requesting quite frequently. Moving a Wordpress site can be tricky as the site's canonical URL is stored in the database and a lot of the internal links are also stored with the full URL (not a relative one). In my experience this can be done in 5 minutes with a few steps but be prepared for a few minutes of downtime:

  1. 使用 PHPMyAdmin 执行数据库的导出(备份)并将其下载到本地计算机(使用 sql 格式备份)可能是最简单的
  2. 在一个好的文本编辑器中打开 sql 文件(Notepad++ 在 Windows 上很好,或者在 Mac 上使用 Text-Wrangler)
  3. 执行查找和替换"在数据库中,找到您当前网址example.myrooturl.com"的所有实例;并将其替换为新网址myrooturl.com/example"
  4. 选择文件中的所有文本并复制到剪贴板(Ctrl+c 或 Cmd+c)
  5. 使用 FTP 程序连接到 FTP 服务器(恕我直言,FileZilla 是最好的)
  6. 在站点的根目录中创建一个名为example"的子文件夹;(其中example"将是网址的/example 部分)
  7. 导航到站点的根目录 - 可能是一个名为example.myrooturl.com"的文件夹;在根目录
  8. 选择该目录中的所有文件
  9. 将这些文件拖到新创建的/example"中文件夹
  10. 返回 PHPMyAdmin 并将第 4 步中复制的 sql 语句粘贴到查询窗口中 - 这可能需要几秒钟到一两分钟的时间,文本才会出现在文本区域中
  11. 执行sql查询

如果遵循了这些步骤并且没有遇到任何问题,这应该就是您需要做的!您应该能够导航到新网址并查看该网站.

If these steps were followed and no issues encountered this should be all you need to do! You should be able to navigate to the new URL and view the site.

编辑

没有考虑两件事:删除在 CPanel 中映射到我们想要使用的子文件夹的子域;以及子文件夹中的站点将嵌套在另一个 Wordpress 安装中的事实.

Two things weren't considered: the removal of the sub-domain which, in CPanel, was mapped to the sub-folder we wanted to use; and the fact that the site in the sub-folder would be nested within another Wordpress installation.

第一项很简单,删除子域映射到文件夹并清除浏览器缓存.第二个更具挑战性,涉及编辑 public_html 文件夹(主站点的文件夹)根目录中的 .htaccess.这是因为当您将 wordpress 站点嵌套在另一个安装中时,Wordpress 可能不允许流量进入嵌套站点 (site.com/site),而是会生成 404 (如果永久链接没有子文件夹名称已存在).这是通过如下编辑 htaccess 来完成的(取自 此处)>

The first item is straightforward, remove the sub-domain mapping to the folder and clear browser cache. The second one is more challenging and involves editing the .htaccess in the root of the public_html folder (the one for the main site). This is because when you have a wordpress site nested in another installation, Wordpress is likely not to allow traffic to go to the nested site (site.com/site) and will instead generate a 404 (if a permalink doesn't already exist for the sub-folder name). This is done by editing the htaccess as follows (taken from here)

 # BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]

# Include in the next line all folders to exclude
RewriteCond %{REQUEST_URI}  !(folder1|folder2|folder3) [NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress 

还值得从嵌套站点中删除旧的 .htaccess,登录 wp-admin,访问 Settings->Permalinks 页面并单击save"在新安装的上下文中重新生成 .htaccess.

It's also worth deleting the old .htaccess from the nested site, logging into the wp-admin, visiting the Settings->Permalinks page and clicking "save" to regenerate the .htaccess in the context of the new installation.

注意@user7357089 建议执行 301 重定向,这是维护任何 SEO果汁"的好主意.您拥有并防止断开的链接.这可以通过 .htaccess 文件轻松完成 - 如果您有这方面的经验,请告诉我您是否需要指导

NB @user7357089 suggests performing 301 redirects, this is a good idea to maintain any SEO "juice" that you have as well as prevent broken links. This can be done easily with the .htaccess file - if you have experience here, let me know if you need guidance

这篇关于将 Wordpress 站点 URL 从子域更改为子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆