0

I have migrated more than 50 websites from Live server to Localhost in my career but have not faced this issue till now. I used ALL IN ONE WP MIGRATION to export the data from live server. I replaced the url during export process.

http://www.example.com/ to http://localhost/example/

I imported the data in my fresh wordpress installation in my localhost. Every thing went fine. My home page loads fine as well. But when I click the home page logo which should redirect to http://localhost/example/ but redirects to http://localhost/dashboard of XAMPP. When I click the menu item -> Services which should redirect to http://localhost/example/services but redirects to http://localhost/services.

I tried changing the Site Address Url and Wordpress Address Url to http://localhost/example/.

My .htaccess file.

# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /example/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /example/index.php [L]
</IfModule>

# END WordPress

Any help is appreciated.

0

go to PHPMyAdmin and click your database then check wp_options -> siteurl, it should be http://localhost/example/

PHPMyAdmin -> open_database -> wp_options -> siteurl

1
  • The correct values are site_url and home_url, both need editing and there might also be hardcoded values in the wp_config.php file.
    – Q Studio
    Jan 24 at 14:20
0

You can do this by running an SQL query in phpMyAdmin. Make sure you have selected your local site’s database and then click on SQL.

enter image description here

In phpMyAdmin’s SQL screen copy and paste this code, make sure that you replace example.com with your live site’s URL and http://localhost/example' with the local server URL of your site.

UPDATE wp_options SET option_value = replace(option_value, 'https://www.example.com', 'http://localhost/example') WHERE option_name = 'home' OR option_name = 'siteurl';
  
UPDATE wp_posts SET post_content = replace(post_content, 'https://www.example.com', 'http://localhost/example');
  
UPDATE wp_postmeta SET meta_value = replace(meta_value,'https://www.example.com','hhttp://localhost/example')

This query will replace refences to your live site’s URL from database and replace it with the localhost URL.

1
  • 3
    The third query can break sites really quick. Whenever WP stores array as data, it gets serialized. Doing simple string replacement inside a serialized string will likely break it. Instead, I suggesst using WP CLI or plugins like Better Search Replace to do this task.
    – kero
    Jan 25 at 10:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.