apache - htaccess get file and extension without path -


i have tried figure out long still cant. have tried htaccess filename without path doesn't work me.

here directory

/www |-- /other.org |-- /example.com     |-- /sub          |-- .htaccess         |-- success.html         |-- /imgs             |-- photo.png 

i trying find if image exists in http://example.com/sub/imgs when there request image or file @ http://example.com/sub. if exists, user redirected success.html. cannot that.

for example if type browser

http://example.com/sub/photo.png 

it checks if file photo.png or kind of image exists in /sub/imgs/photo.png, not exist , should not exist in /sub directory.

http://example.com/sub/imgs/photo.png 

the redirected output success.html if exists.

http://example.com/sub/success.html 

i tried

rewritecond %{document_root}/sub%{request_uri} -f rewriterule (.*)\.(gif|jpg|jpeg|png)$ success.html 

but %{request_uri} /sub/photo.png output http://example.com/sub/imgs/sub/photo.png. there isn't request can file name or after last slash (/). possible file name photo.png can do:

rewritecond %{document_root}/sub/imgs%{file_name} -f rewriterule (.*)\.(gif|jpg|jpeg|png)$ success.html 

is there way working?

you can try rule in sub/.htaccess:

rewriteengine on rewritebase /sub/  rewritecond %{document_root}/sub/imgs/$1 -f rewriterule ^(.+\.(?:jpe?g|png|gif|tiff|ico))$ success.html [l,nc] 

Comments