.htaccess RewriteRule for image URL

前端 未结 1 1993
梦毁少年i
梦毁少年i 2020-12-22 13:16

At the moment i have the following .htaccess rewrite rule:

RewriteCond %{HTTP_HOST} ^blitz.example.com.s3-ap-southeast-1.amazonaws.com$
RewriteRule ^([0-9])(         


        
相关标签:
1条回答
  • 2020-12-22 13:32

    You are trying to capture way to much. First the rewrite engine does not pass the full URL but only the URI, so the name http://blitz.example.com.s3-website-ap-southeast-1.amazonaws.com will never, ever be captured by any RewriteRule, so forget about it. Second, you capture the name of the image, which seems to be irrelevant in our case.

    Judging by the comment, the image is located on a CDN (Amazon S3). If you want to convert http://blitz.example.com.s3-website-ap-southeast-1.amazonaws.com/3478-product_list_default/green-army-combats-type-i.jpg(1) to http://blitz.example.com.s3-website-ap-southeast-1.amazonaws.com/img/p/3/4/7/8/3478-product_list_default.jpg(2): it is a job for the S3 server. Why is this? It's because the HTTP request for (1) will be directly send to the S3 server by the web-browser trying to load the image. So the .htaccess has to be put on the S3 server and mod_rewrite enabled.

    On the plus side, your regex is correct : Regex101

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