I’ve been looking over many examples but just can’t get my head around this, may be it isn’t possible. I’ve inherited a mess of a WordPress site.
I have this DIR structure, WordPress:
/wp-content/uploads/
/wp-content/uploads/2011
/wp-content/uploads/2012
/wp-content/uploads/Organised
/wp-content/uploads/Organised/0-9
/wp-content/uploads/Organised/A
/wp-content/uploads/Organised/B
/wp-content/uploads/Organised/ and so on ... to Z
Basically there were over 93,000 files in the /wp-content/uploads/ folder, and some in the 2011, and 2012 folders. I need to move the 93,000 files so decided to make the “Organised” folder with folders in there reflecting the first letter/number of potential files.
While this isn’t an issue, with moving them that is, I need to make sure external requests can still access those files based on the old URL.
So:
/wp-content/uploads/APicture.jpg
Will Rewrite to:
/wp-content/uploads/Organised/A/APicture.jpg
While still allowing access to actual URLS like:
/wp-content/uploads/2012/AnotherPicture.jpg
I thought a Rewrite URL like this would work but it doesn’t and I have tried many variations, maybe it just can’t work like this?
RewriteRule ^/wp-content/uploads/([^/]+)(\.png|\.jpg|\.bmp|\.gif)$ /wp-content/Organised/T/$1$2
Note: For testing I was checking a URL /wp-content/uploads/taylor-swift-harry-styles.jpg such is why I hardcoded the resulting rewrite URL but I realise it needs to be changes to match the initial letter.
Thanks for all your help.
You may try this:
It will redirect URLs like this one:
http://example.com/wp-content/uploads/Taylor-swift-harry-styles.jpgBut not like this one:
http://example.com/wp-content/uploads/2012/Taylor-swift-harry-styles.jpgTo:
http://example.com/wp-content/Organised/T/Taylor-swift-harry-styles.jpgWhere directory
Tis the first character of the file name. It can be a single digit or a single letter.It will keep the letter case, though. For example, if the letter is in lower case, the mapped directory will be
tand must exist. Same happens when the letter is in upper case.