Apache - rewrite jpg to URL with .htaccess

前端 未结 2 503
暖寄归人
暖寄归人 2021-01-21 15:59

Hi im trying to do redirect from .jpg file to specific URL address but it don\'t work. Can sb help me?

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI}          


        
相关标签:
2条回答
  • 2021-01-21 16:44

    Try this :

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_URI} ^/(.*)\.jpg [NC]
    RewriteRule ^up/(.*)\.jpg/?$ /file?name=$1.jpg [R=301,L]
    
    0 讨论(0)
  • 2021-01-21 16:45

    RewriteCond is totally redundant here, you can match this pattern in RewriteRule itself. Try this rule:

    RewriteEngine On
    RewriteBase /
    
    RewriteRule ^up/(.+?\.jpe?g)$ file?name=$1 [NC,QSA,L]
    

    Also you may not need R=301 here since you don't want to expose your internal handling of image to clients.

    0 讨论(0)
提交回复
热议问题