admin管理员组文章数量:1302871
I was using all images as webp files for performance, however I've stopped using and deleted them (only .webp files) all from FTP. Now having problems with 404 errors. I would like to redirect all .webp files to jpg, png, gif, etc.
For example:
.jpg.webp
.jpeg.webp
.gif.webp
.png.webp
TO...
.jpg
.jpeg
.gif
.png
Redirection plugin:
Source URL: ^(?!.*-[0-9]{1,4}x[0-9]{1,4}).*\.(?:jpg.webp)
Target URL: /$1/$2/$3.$4
And it didn't work. Also, I tried it with htaccess but again, it didn't work. Is there a way to arrange that?
I was using all images as webp files for performance, however I've stopped using and deleted them (only .webp files) all from FTP. Now having problems with 404 errors. I would like to redirect all .webp files to jpg, png, gif, etc.
For example:
https://www.example/wp-content/uploads/2019/04/file.jpg.webp
https://www.example/wp-content/uploads/2019/04/file.jpeg.webp
https://www.example/wp-content/uploads/2019/04/file.gif.webp
https://www.example/wp-content/uploads/2019/04/file.png.webp
TO...
https://www.example/wp-content/uploads/2019/04/file.jpg
https://www.example/wp-content/uploads/2019/04/file.jpeg
https://www.example/wp-content/uploads/2019/04/file.gif
https://www.example/wp-content/uploads/2019/04/file.png
Redirection plugin:
Source URL: ^(?!.*-[0-9]{1,4}x[0-9]{1,4}).*\.(?:jpg.webp)
Target URL: https://www.example/wp-content/uploads/$1/$2/$3.$4
And it didn't work. Also, I tried it with htaccess but again, it didn't work. Is there a way to arrange that?
Share Improve this question asked Feb 18, 2021 at 2:58 user179248user179248 1- Browsers will try to reach the files directly, bypassing WP. You'll need to solve this on the server (.htaccess) level. – cjbj Commented Feb 19, 2021 at 10:56
1 Answer
Reset to default 1If I'm reading it right, your regex has only two items in ()
, which means that only $1
and $2
have any meaning.
I copied your sample text and went to https://regex101/ (note: this is not an endorsement) to try to assemble a regex that'll cover all your images. Here's what I ended up with:
Pattern: ^(.*\/[0-9]{1,4}\/[0-9]{1,2}\/)([^\.]+)\.(jpg|jpeg|gif|png)\.webp
Replacement: $1$2.$3
This is using the PCRE standard, which is apparently used in PHP < 7.3. You may need to tweak the regex if you're using PHP 7.3 or 7.4 (or higher), or if you want to use it in a .htaccess
file.
本文标签: url rewritingHow to redirect Webp files
版权声明:本文标题:url rewriting - How to redirect Webp files? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741742020a2395327.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论