404 error and redirect after moving wordpress site

2019-07-29 05:00发布

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

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?

4条回答
We Are One
2楼-- · 2019-07-29 05:24

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');

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' );

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');
查看更多
小情绪 Triste *
3楼-- · 2019-07-29 05:24

You need to follow this guide to restore website

查看更多
Deceive 欺骗
4楼-- · 2019-07-29 05:25

I think you should update the site URL. there are two ways to do this

  • by Editing the wp-config.php file :

    define('WP_HOME','http://example.com');
    define('WP_SITEURL','http://example.com');
    
  • or go to Settings->General and change both of WordPress Address and Site Address then click update

查看更多
一夜七次
5楼-- · 2019-07-29 05:44

In addition to MrRobot's answer, you should edit your mysql dump file before importing inside. Replace all old URLs to your new URLs . You can use notepad or sublime text or whatever...

查看更多
登录 后发表回答