Copied site to localhost, but URL base is not correct for links or images

I just pulled a copy from a live site and installed locally using XAMPP. The directory is:

127.0.0.1/website-files/websitename

Read More

The homepage pulls up just fine, but no images load. The links do not work either. Image and link URLs have not updated to reflect the new directory. They still show as:

/categoryname/pagename

Instead of

/website-files/websitename/categoryname/pagename

The site is wordpress, and the general settings are updated:

WordPress Address http://127.0.0.1/website-files/websitename

Site Address http://127.0.0.1/website-files/websitename

I added this to functions.php, which I assumed would do all the changes I needed:

update_option('siteurl','http://127.0.0.1/website-files/websitename');
update_option('home','http://127.0.0.1/website-files/websitename');

.htaccess looks like this:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /website-files/websitename/
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /website-files/websitename/index.php [L]
</IfModule>

I run into an issue every time I move a website to a new dev server, but this one is a first. What am I missing here?

Related posts

Leave a Reply

2 comments

  1. Avoid using a leading / for any links for your website, so instead of:

     <a href="/foo">foo</a>
     <img src="/images/bar.jpg">
    

    Do this:

     <a href="foo">foo</a>
     <img src="images/bar.jpg">
    

    And finally, you might want to experiment with adding a “base href” tag to the top of your HTML, which would have a different value depending on what server you’re running on. A quick google for base href will teach you how this works.

    You might have to restructure how you build webpages to make this happen. That’s simply how things are if you want to be able to run a single website on more than one server.

    If you’re using WordPress or another similar open source framework, you might be screwed. Some of them are simply incapable of operating on more than one server.

  2. Try to confirm that home and siteurl have been updated in your local database’s wp_options table.

    Alternately you can can try setting WP_HOME and WP_SITEURL to point to your local files in wp-config.php. This overrides the settings in the options table.

    define('WP_HOME', 'http://127.0.0.1/website-files/websitename');
    define('WP_SITEURL', 'http://127.0.0.1/website-files/websitename');