404 error and redirect after moving wordpress site from live to localhost

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.

Read More

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?

Related posts

4 comments

  1. 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');
    
  2. 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

  3. 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…

Comments are closed.