简体   繁体   中英

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:

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.

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM