htaccess的重写规则的图片网址

编程入门 行业动态 更新时间:2024-10-15 20:20:39
本文介绍了htaccess的重写规则的图片网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

目前,我有以下的.htaccess重写规则:

的RewriteCond%{HTTP_HOST} ^ blitz.example.s3-ap-southeast-1.amazonaws $ 重写规则^([0-9])([0-9])([0-9])([0-9])(\ - [_ A-ZA-Z0-9 - ] *)( - [0 ?-9] +)/.+ \ JPG $%{ENV:的RewriteBase} IMG / P / $ 1 / $ 2 / $ 3 / $ 4 / $ 1 $ 2 $ 3 $ 4 $ $ 5 6.JPG [L]

我想重写以下URL,使其指向实际的URL(见下面第2个链接):

blitz.example.s3-website-ap-southeast-1.amazonaws/3478-product_list_default/green-army-combats-type-i.jpg

在哪里,因为我需要创建一个重写规则指向哪个才是真正的实际的URL:

blitz.example.s3-website-ap-southeast-1.amazonaws/img/p/3/4/7/8/3478-product_list_default.jpg

谁能帮助我?我真的很困惑这个重写规则和正则表达式。

修改

我想使用像以下网址:

blitz.example.s3-website-ap-southeast-1.amazonaws/3478-product_list_default/green-army-combats-type-i.jpg

和使用类似如下的另一个域改写它:

blitz.example.s3-website-ap-southeast-1.amazonaws/img/p/3/4/7/8/3478-product_list_default.jpg

到目前为止,如果我使用下面的HTML标签

< IMG src="blitz.example.s3-website-ap-southeast-1.amazonaws/3478-product_list_default/green-army-combats-type-i.jpg">

返回404

编辑2

有趣的是下面的code也将返回404错误

< IfModule mod_rewrite.c> 的RewriteCond%{HTTP_HOST} ^ blitz.example.s3-ap-southeast-1.amazonaws $ 重写规则^([0-9] +)([0-9] +)([0-9] +)([0-9] +)(*) - ([A-ZA-Z0-9 _ \ - /.]+)/([a-zA-Z0-9_\-/.]+)$ IMG / P / $ 2 / $ 3 / $ 4 / $ 10 / $ 2 $ 3 $ 4 $ 5- $ 6.JPG [L] < / IfModule>

修改3

出于绝望,我只放下面的code对我的.htaccess:

< IfModule mod_rewrite.c> 重写规则^([0-9] +)([0-9] +)([0-9] +)([0-9] +)(*) - ([A-ZA-Z0-9 _ \ - /.]+)/([a-zA-Z0-9_\-/.]+)$ IMG / P / $ 2 / $ 3 / $ 4 / $ 10 / $ 2 $ 3 $ 4 $ 5- $ 6.JPG [L] < / IfModule>

有没有其他的code在.htaccess,但它仍然会返回404。

解决方案

正在试图捕捉办法不多。首先重写引擎不通过完整的URL,但只有URI,故得名 blitz.example.s3-website-ap-southeast-1.amazonaws 将永远不会被任何重写规则,所以忘掉它被捕获。其次,你捕捉到的图像,这似乎是无关紧要在我们的例子中的名称。

在注释来看,图像位于一个CDN(亚马逊S3)。如果你想转换blitz.example.s3-website-ap-southeast-1.amazonaws/3478-product_list_default/green-army-combats-type-i.jpg(1)至blitz.example.s3-website-ap-southeast-1.amazonaws/img/p/3/4/7/8/3478-product_list_default.jpg(2):它是为S3的服务器的工作。为什么是这样?这是因为对于HTTP请求(1)将被直接发送到S3服务器上的Web浏览器尝试加载图像。因此,的.htaccess ,必须把S3服务器上,的mod_rewrite 启用。

从积极的一面,你的正则表达式是正确的: Regex101

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

RewriteCond %{HTTP_HOST} ^blitz.example.s3-ap-southeast-1.amazonaws$ RewriteRule ^([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$1$2$3$4$5$6.jpg [L]

I am trying to rewrite the following URL so that it points to the actual URL (see 2nd link below):

blitz.example.s3-website-ap-southeast-1.amazonaws/3478-product_list_default/green-army-combats-type-i.jpg

Where as i need to create a RewriteRule that points to the real actual URL which is:

blitz.example.s3-website-ap-southeast-1.amazonaws/img/p/3/4/7/8/3478-product_list_default.jpg

Can anyone help me with this ? I am really confused with this RewriteRule and regex.

EDIT

I want to use URLs like the followings :

blitz.example.s3-website-ap-southeast-1.amazonaws/3478-product_list_default/green-army-combats-type-i.jpg

and rewrite it with another domain like the followings :

blitz.example.s3-website-ap-southeast-1.amazonaws/img/p/3/4/7/8/3478-product_list_default.jpg

So far if i use the following html tag

<img src="blitz.example.s3-website-ap-southeast-1.amazonaws/3478-product_list_default/green-army-combats-type-i.jpg">

it returns 404

EDIT 2

Interestingly enough the following code also returns 404 error

<IfModule mod_rewrite.c> RewriteCond %{HTTP_HOST} ^blitz.example.s3-ap-southeast-1.amazonaws$ RewriteRule ^(.*)([0-9]+)([0-9]+)([0-9]+)([0-9]+)-([a-zA-Z0-9_\-/.]+)/([a-zA-Z0-9_\-/.]+)$ img/p/$2/$3/$4/$5/$2$3$4$5-$6.jpg [L] </IfModule>

EDIT 3

Out of desperation, i put only the following code on my .htaccess:

<IfModule mod_rewrite.c> RewriteRule ^(.*)([0-9]+)([0-9]+)([0-9]+)([0-9]+)-([a-zA-Z0-9_\-/.]+)/([a-zA-Z0-9_\-/.]+)$ img/p/$2/$3/$4/$5/$2$3$4$5-$6.jpg [L] </IfModule>

There is no other code in .htaccess, yet it still returns 404.

解决方案

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 blitz.example.s3-website-ap-southeast-1.amazonaws 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 blitz.example.s3-website-ap-southeast-1.amazonaws/3478-product_list_default/green-army-combats-type-i.jpg(1) to blitz.example.s3-website-ap-southeast-1.amazonaws/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

更多推荐

htaccess的重写规则的图片网址

本文发布于:2023-11-02 00:15:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1550816.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重写   规则   网址   图片   htaccess

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!