Htaccess redirect rule info redirect rewrite

31 Views Asked by At

I have to set a rule on my htaccess file that redirects me all the images ex: img_4324_r.jpg to img_4324_s.jpg

all images

2

There are 2 best solutions below

0
Cillian Collins On
RewriteRule ([^.]+\.(jpe?g|gif|bmp|png)) /img_4324_s.jpg [R=301,L,NC]

Should work, not 100% sure what you're asking for though.

0
fab2s On

For your exact example:

RewriteRule ^img_([0-9]+)_r\.jpg$ img_$1_s.jpg [R=301,L,NC]

if you have several extension with the same pattern:

RewriteRule ^img_([0-9]+)_r\.(jpe?g|png|gif)$ img_$1_s.$2 [R=301,L,NC]

Only to jpg:

RewriteRule ^img_([0-9]+)_r\.(jpe?g|png|gif)$ img_$1_s.jpg [R=301,L,NC]

You can repeat for each patterns if you have others, just capture what you need and use it

You also may need to add this at the top of you .htaccess:

RewriteEngine On
RewriteBase /