While setting up a local WordPress site, if I have a relative link like this:
<img src=”/wp-content/themes/Tree/assets/images/logo.svg” alt=”logo.svg” width=”95″ height=”29″>
When I click on it, it will go to:
http://localhost/wp-content/themes/Tree/assets/images/logo.svg
instead of
http://localhost/mysite_local/wp-content/themes/Tree/assets/images/logo.svg
`.htaccess` looks like this
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /mysite_local/
RewriteRule ^index\.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /mysite_local/index.php [L]
</IfModule>
# END WordPress
I’m using XAMPP on Windows 10 to setup a local WordPress development. All other steps have been performed successfully, and this is the last thing that’s left not working.
* I tried going to Permalinks, and saving, but it did not help.
* I tried changing `DocumentRoot` in `httpd.conf` to:
`DocumentRoot “C:/xampp/htdocs/mysite_local”`
`<Directory “C:/xampp/htdocs/mysite_local”>`
But I get Error 500, apache `error.log` says this:
>AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use ‘LimitInternalRecursion’ to increase the limit if necessary. Use ‘LogLevel debug’ to get a backtrace.
* I tried adding this to `wp-config.php`, but it didn’t help
`define(‘WP_HOME’,’http://example.com’);`
`define(‘WP_SITEURL’,’http://example.com’);`
* Cleared cache/cookies/etc and restarted server multiple times while trying this ofc
How should I fix this?
[ad_2]
WordPress sucks with relative links – a lot of them are beyond your control, so when migrating to live, just convert the absolute link strings as part of that process i.e. with either WP CLI search-replace or Better Search Replace plugin, or a migration plugin like WP Vivid
This isn’t a WordPress issue. Your HTML is telling your browser to tell your server that it wants something from a folder called ‘wp-content’ in the document root of your server and the server dutifully tries to return that document.
There are several ways to ‘solve’ this:
1) Like Jack of All Trades says, replace the links in the database. This has the disadvantage that you need to do that again once you copy your changes to a different environment, i.e. a production server (assuming local is for development).
2) Host your site on a local sub-domain, e.g. mydomain,local. This requires changes in your server settings and your hosts file.
3) Write a filter (or find a plugin that defines one) that replaces relative links in content by different paths.
4) If your relative links are defined in PHP (i.e. in theme templates and such), prefix them with the proper functions that read out the values of site_url or home_url to define the link that is served, e.g. get_template_directory_uri() and the like.
Assuming your example wasn’t entirely made up, this last step may be the one you need.