Davide Infsercom
Davide Infsercom

Reputation: 39

Htaccess redirect rule info redirect rewrite

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

Upvotes: 0

Views: 30

Answers (2)

fab2s
fab2s

Reputation: 868

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 /

Upvotes: 1

Cillian Collins
Cillian Collins

Reputation: 728

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.

Upvotes: 0

Related Questions