I have a bunch of posts that contain images with urls that follow this pattern:


I've imported the posts into a new install of wordpress on the same domain with file structure where the files now reside at


Because "example_directory" is now a category slug, I cannot simply update the new directory structure to mirror the old one.

How can I make the files inside new_directory appear when my browser tries to visit urls at directory/files?

1 Answer 1


I believe I've found the solution. I add the following

RewriteRule ^example_directory/files/(.*) new_directory/$1

to my WordPress .htaccess rules like so:

RewriteEngine On
RewriteBase /
RewriteRule ^example_directory/files/(.*) new_directory/$1
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

I couldn't get it working before and I think the key was moving the new RewriteRule directive to the line directly following RewriteBase /

  • 1
    Make sure you add your custom Rewrite commands before the # BEGIN WordPress otherwise it'll get removed when you update permalinks. Feb 26, 2021 at 8:40
  • "the new RewriteRule directive to the line directly following RewriteBase /" - The order of the directives with respect to RewriteEngine and RewriteBase does not matter (surprisingly). The important bit is that the directive is before the other directives that now following (ie. the WordPress front-controller). As Sunil pointed out, you should place your custom directive before everything - at the top of the file (you do not need to repeat the RewriteEngine or RewriteBase directives).
    – MrWhite
    Feb 26, 2021 at 17:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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