简体   繁体   English

htaccess重定向规则信息重定向重写

[英]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 我必须在htaccess文件上设置一条规则,将所有图像重定向到img_4324_r.jpg到img_4324_s.jpg

all images 所有图片

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: 仅限于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: 您可能还需要在.htaccess的顶部添加以下内容:

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

应该可以,但是不能100%确定您的要求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM