apache - How to fetch the filename of an image and rewrite the path removing the file extension(jpg,png, etc.) using htaccess? -
i able partially htaccess code below, turns out need remove image's file extension, such .jpg, .png, etc. new url well.
here htaccess code:
rewritecond %{request_filename} .*jpg$|.*gif$|.*png$ [nc] rewritecond %{http_referer} !mysitee\.com [nc] rewriterule ([^/]*\.(jpg|gif|png))$ http://mysitee.com/?attachment=$1
for example, 1 of many images have is:
http://mysitee.com/wp-content/uploads/2015/10/myimage.jpg
and when use code new url this:
http://mysitee.com/?attachment=myimage.jpg
how can make doesn't add path before image? want this:
http://mysitee.com/?attachment=myimage
a little guesswork , got working!
rewriterule ([^/]*)\.(jpg|gif|png)$ http://thetechreader.com/?attachment=$1
i moved \.(jpg|gif|png)
outside of parenthesis, , seems work.
i leave question open though if have better answer.
Comments
Post a Comment