将 wordpress 站点从 live 移动到本地主机后出现 404 错误和重定向 [英] 404 error and redirect after moving wordpress site from live to localhost

查看:40
本文介绍了将 wordpress 站点从 live 移动到本地主机后出现 404 错误和重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一位新客户要求为其网站添加新主题(wordpress 4.4.3).

A new client requested a new theme for his website (wordpress 4.4.3).

我复制了文件和数据库,这样我就可以在 wamp 上工作,这样我就不必关闭网站,我现在遇到了一些问题:当我访问网站时,我收到404 找不到请求的页面"和所有其他链接都转到实时站点.

I copied the files and database so I can work on wamp so I won't have to take the site down and I am now experiencing some problems: when I access the website I get "404 The requested page could not be found" and all other links go to the live site.

网站上有一些重定向插件,但停用它们并没有解决我的问题,甚至停用所有插件似乎也不起作用.我还通过更改为默认值然后返回帖子名称但没有更改来更新永久链接.

There are some redirecting plugins on the website but deactivating them hasn't solved my problem, even deactivating all plugins doesn't seem to work. I also updated the permalinks by changing to default and then back to post name but no change.

有人为我提供解决方案吗?

Does anyone have a solution for me?

推荐答案

将以下代码添加到 wp-config.php 文件中.这将覆盖网站网址和主页网址.

Add the following code to wp-config.php file. this will override site url and home url.

define('WP_HOME','http://example.com');
define('WP_SITEURL','http://example.com');

现在,您在活动主题的functions.php 文件中添加了另外2 行,因此这将覆盖您的主题选项.

Now, You have add more 2 lines to your functions.php file of your active theme, so this will override your theme options.

update_option( 'siteurl', 'http://example.com' );
update_option( 'home', 'http://example.com' );

但这是临时解决方案,您需要查找和替换 url 表单数据库,您也可以使用 sql 查询来更新.以下查询将很有用

But this the temporary solution , you need to find and replace url form database you can also use sql query to update. Following query will useful

UPDATE wp_options SET option_value = replace(option_value, 'http://olddomain.com', 'http://newdomain.com') WHERE option_name = 'home' OR option_name = 'siteurl';

UPDATE wp_posts SET guid = replace(guid, 'http://olddomain.com','http://newdomain.com');

UPDATE wp_posts SET post_content = replace(post_content, 'http://olddomain.com', 'http://newdomain.com');

UPDATE wp_postmeta SET meta_value = replace(meta_value, 'http://olddomain.com', 'http://newdomain.com');

这篇关于将 wordpress 站点从 live 移动到本地主机后出现 404 错误和重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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