I redesigned an old (static) website to WordPress CMS. Now that site is WordPress based with ‘blog’ as a page displaying all posts. On previous (static) version, they already had a separate WP blog inside /blog directory. I imported all old blog posts to our new WP setup but problem is with images. On old blog, images inside posts had source like http://www.example.com/blog/wp-content/uploads/../x.jpg
But once all posts were imported to new site, these image paths didn’t change in imported posts and now are all broken links.
I tried fixing this issue by creating an empty folder blog
on root, with only wp-content/uploads
folder in it so paths to old images keep working. But now my new blog page is not working. Instead of showing /blog
posts, it shows contents of blog
directory. This is because of .htaccess which knows that /blog
is an existing directory which exists and doesn’t pass request to index.php.
Now the only solution is to tell .htaccess to consider only those ‘/blog’ directory requests which are image URLs and the file exists. And pass rest of requests to index.php.
Default .htaccess content looks like:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
How do I achieve this?
Thanks.
This is not answering the exact question you posed, but as as far as I am concerned, your current attempt is the wrong approach to solve the problem of wrong image paths after moving anyway.
Rather than what you are attempting to do, either replace the image paths in the database, or redirect those.
While replacing/updating image paths can be done manually, there’s (a minimum of) two excellent plugins that will do the job. Take a look at either
As for rewriting the paths, see the Redirection plugin. Also fairly simple to use.