mod_rewrite to mask url

I’m using WP, & I want to use a mod_rewrite rule such that all images from wp-content/uploads folder shows a different URL.

eg:

Read More

www.example.com/wp-content/uploads/image.jpeg —>
www.example.com/media/image.jpeg

I’ve placed a rule in .htaccess but it returns a 404 error.

RewriteRule ^wp-content/uploads/(.*)$ /media/$1 [L,NC,R]

Here’s the .htaccess code.

Related posts

Leave a Reply

1 comment

  1. Are you looking for something like this (all of these rules need to be before the default wordpress rules):

    RewriteCond %{THE_REQUEST}  /+wp-content/uploads/([^? ]+)
    RewriteRule ^ /media/%1 [L,R=301]
    
    RewriteCond %{REQUEST_URI} ^/media/(.+)$
    RewriteCond %{DOCUMENT_ROOT}/wp-content/uploads/%1 -f
    RewriteRule ^media/(.+)$ /wp-content/uploads/$1 [L]