简体   繁体   English

如何将WordPress移动到子目录

[英]How to move wordpress to subdirectory

I am moving a brand new Wordpress site from root "/" directory to a subdirectory "/wordpress/" using the following guide: 我使用以下指南将全新的Wordpress网站从根目录“ /”移动到子目录“ / wordpress /”:

https://codex.wordpress.org/Giving_WordPress_Its_Own_Directory https://codex.wordpress.org/Giving_WordPress_Its_Own_Directory

Sadly, there are problems with these steps. 可悲的是,这些步骤存在问题。 Step (4) indicates we need to update "Site address (URL)" which updates wp_option "siteurl" to " http://localhost/ " but will leave "home" in tact ( http://localhost/wordpress ). 步骤(4)表示我们需要更新“站点地址(URL)”,该站点地址会将wp_option“ siteurl”更新为“ http:// localhost / ”,但仍将“ home”保留为原样( http:// localhost / wordpress )。

This is causing issues as I can no longer login to wp-admin. 这引起了问题,因为我无法再登录到wp-admin。 By setting both "siteurl" back to " http://localhost/wordpress " I am finally able to access wp-admin, but now the pages are throwing 404's and cannot be found. 通过将两个“ siteurl”都设置回“ http:// localhost / wordpress ”,我终于可以访问wp-admin了,但是现在这些页面抛出了404,并且无法找到。 Not only that, but all URL's have /wordpress/ in the path now which isn't a slug I want in my pages. 不仅如此,所有URL现在在路径中都带有/ wordpress /,这并不是我想要在页面中显示的。 In other words, I am fine with having wp-admin accessible via http://localhost/wordpress/wp-admin/ but public pages should be accessible using this format: http://localhost/page-1/ 换句话说,我可以通过http:// localhost / wordpress / wp-admin /访问wp-admin,但应该使用以下格式访问公共页面: http:// localhost / page-1 /

Is there a way to move WP to a subdirectory without all these consequences? 有没有一种方法可以将WP移到子目录而不会产生所有这些后果?

Step 1: Export your database as .sql open the file using text editor. 步骤1:将数据库导出为.sql ,使用文本编辑器打开文件。 find the http://localhost and replace with http://localhost/wordpress and again import it. 找到http://localhost并替换为http://localhost/wordpress然后再次导入。 This will work.! 这将起作用。

Step 2: Update siteurl and home 第2步:更新siteurlhome

Next you need to change the location of your site in the database. 接下来,您需要更改站点在数据库中的位置。

In wp_options, locate siteurl and home. 在wp_options中,找到siteurl和home。 Usually these records are at the top of the table on line 1 and 2. For siteurl, click the field under option_value and replace the old domain with your new domain name. 通常,这些记录在表的第1行和第2行的顶部。对于siteurl,请单击option_value下的字段,然后将旧域替换为新域名。 Press enter to save. 按Enter保存。 Do the same for home. 在家做同样的事情。

Step 3: Fix permalinks (Optional) 步骤3:修复固定链接(可选)

If you experience that you get a 404 error when you try to open links on your site, the Permalinks are broken. 如果您在尝试打开网站上的链接时遇到404错误,则永久链接已损坏。 Luckily it is very easy to fix this. 幸运的是,解决此问题非常容易。

Log in to your WordPress dashboard. 登录到WordPress仪表板。 Click Settings and then Permalinks Scroll down and click Save Changes. 单击设置,然后永久链接向下滚动并单击保存更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM