Question

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

https://example.com/example_directory/files/2019/04/file.png

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

https://example.com/new_directory/2019/04/file.png

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?

Was it helpful?

Solution

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 /

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top