I am working on a site migration and I need to set up some redirects for image files. Certain image path requests will come in to root-level subdirectories
and I need to put /new_directory/ as the first directory for all of them, like so:
Old site request -> new request
website.com/dir1/image.png -> website.com/new_directory/dir2/subdir1/image.gif
website.com/dir2/subdir1/image.gif -> website.com/new_directory/dir2/subdir1/image.gif
Here's what I have so far, but it doesn't appear to be working. What am I missing?
RewriteCond %{HTTP_REQUESTURI} (dir1|dir2|dir3)(.+?)(jpg|png|gif|jpeg) [NC,OR]
RewriteCond %{HTTP_REQUESTURI} (dir4|dir5|dir6)(.+?)(jpg|png|gif|jpeg) [NC,OR]
RewriteCond %{HTTP_REQUESTURI} (dir7|dir8|dir9)(.+?)(jpg|png|gif|jpeg) [NC]
RewriteRule ^(.+?)$ /new_directory/$1 [R=301,L]
I have several RewriteCond lines broken up because my actual list of directories is quite long, and I want the rules to fit on one screen width.