Y
Y
Ysery2020-10-09 21:24:21
htaccess
Ysery, 2020-10-09 21:24:21

How to show a different image using a command in htaccess?

Good day, dear experts.

There is a folder on the hosting, there are a lot of pictures in it, the names are random, but always in pairs (the same, just different resolution - 40 and 80 pixels), with the ending x40 and x80. For example:

1111111x40.png
1111111x80.png
2222222x40.png
2222222x80.png
3333333x40.png
3333333x80.png
And so on.

If a request comes from the browser to open an image under the name 2222222x40.png, then give (not redirect, namely give) another one, under the name this-image-x40.png followed by a request 2222222x80.png and then give this-image-x80 .png
And the next pair of requests, 1111111x40.png - also give this-image-x40.png and accordingly 2222222x80.png - give this-image-x80.png

Etc.

I will make a list with specific names-pairs that should be given by another picture.

What will this command look like?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2020-10-09
@Ysery

RewriteRule ^(1111111|2222222|3333333)(x[48]0\.png)$ this-image-$2 [L]

You can move the checks to RewriteCond.
RewriteCond $1 =1111111 [OR]
RewriteCond $1 =2222222 [OR]
RewriteCond $1 =3333333
RewriteRule ^(.+)(x[48]0\.png)$ this-image-$2 [L]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question