title: custom image url rewrite to directory using .htaccess
body: <p>I have currently mod_rewrite enabled on <a href="https://abcd.com/images/12345_image_67890.jpg" rel="nofollow noreferrer">https://abcd.com/images/12345_image_67890.jpg</a> which streams the image through a PHP file image.php</p>
  <p>Now what I am trying to do is rewrite the <a href="https://abcd.com/images/12345_image_67890.jpg" rel="nofollow noreferrer">https://abcd.com/images/12345_image_67890.jpg</a> to the source directory/file -&gt; image_directory/4590/12345.jpg</p>
  <pre><code>12345 in the filename12345_image_67890.jpg is image_id
  67890 in the filename 12345_image_67890.jpg is post_id
  </code></pre>
  <p>The problem: if you see the subdirectory 4590 inside the image_directory which was dynamically created while uploading the file and 4590 directory name was generated using the last 2 digits of image_id and post_id
  How can I get 45, 90 and 12345 from this url -&gt; <a href="https://abcd.com/images/12345_image_67890.jpg" rel="nofollow noreferrer">https://abcd.com/images/12345_image_67890.jpg</a> and rewrite it to image_directory/4590/12345.jpg
  I know this is confusing, let me know if you have any questions.</p>