If 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.com/ (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.
Related Posts:
- rewrite rules and querystring
- add_rewrite_rule: $matches var not replaced by captured value
- Custom permalinks with NextGEN Gallery
- How to change default page slug?
- Will references to ugly links automatically redirect to their pretty url permalink?
- How do I add a add_rewrite_rule without it redirecting?
- WordPress URL rewrite regex
- WP Login forms action URLs displayed as pretty URLs in browser (ex with Restore Password)
- Sub domain redirection to taxonomy
- Redirecting all old links from previous EE site to new WP site in one go?
- Server (WordPress) redirects files that are not supposed to (using htaccess)
- Rewrite WordPress Custom URL
- WordPress removes spaces in URL on pagination
- Remove all categories from URL
- Custom rewrite rule
- Home page with Polylang redirects to other page [closed]
- expecting 404 but redirecting to post with url subdirectory in post title
- Rewrite of URL with ‘[‘ ‘]’ or ‘(‘ ‘)’ as literals
- Alias ‘wp-content’ directory to something shorter (framework?)
- Is there a ‘rake routes’ for wordpress?
- Remove Query String from URL on Redirect – Redirection Plugin
- How to properly rewrite url by custom var
- Rewrite rule to load images from production does nothing
- add_rewrite_rule fro html to another url not working
- Double domain name in category URL-s
- optimize wordpress rewrite rule regex
- WordPress redirects non-existing url to existing ones – how to disable
- Rewrite Preview URL to include index.php
- How to disable URL rewriting for specific URLs?
- Custom rewrite_rules – only pass numbers and not alphabetic characters
- Can I change default registration link (without htaccess)?
- How do I display only the parent page in the url
- How to remove wordpress directory slash
- Wildcard forward all posts and pages with few exceptions
- Redirect HTTP to HTTPS for all sub domains (blog posts)
- Rewrite query string to path
- How to redirect large amount of URLs?
- Redirecting /px/?q=x to /px/x/
- How do I only allow downloads that are referred from my domain?
- URL redirect on updating the post date
- How to redirect a link to a new link?
- Rewrite vs Redirect from ?p={ID}
- 301 Redirect all posts urls from .html to / (without .html)
- Is WordPress API visible from PHP file called in htaccess
- How can I reduce the number of rewrite rules?
- Re-directing URLs with dates to URLs without dates
- Redirect htaccess [closed]
- WP in subfolder hidden by htaccess, but media links show the subfolder
- 301 Rewriting htaccess
- 404 redirect based on url
- How are rewrite rules applied in WordPress?
- WordPress 3.1.2 Network Enabled non-www to www
- Redirect to new domain that serves new and different content
- add_rewrite_rule with optional parameters
- Redirect users with “.” (dot) in their username and replace with “-” (dash) to correct profile
- Rewrite rule regex help required
- Redirect empty search to another page
- Remove part from dynamic url and redirect
- Fresh install redirects to www, breaking page loads
- Broken page redirect
- Make URL like /fr/something display same as /something
- Remove trailing slash
- taxonomy term in URL slug won’t forward to the correct term for custom post like it does for default categories/normal posts
- Error 404 wordpress redirecting URL
- How to create short urls for sharing and downloadable content?
- Redirect A URL Pattern In WordPress Using .htaccess
- URLs ending with number higher than 2147483647 redirects to to domain.com/2147483647
- Migration from old CMS to WordPress 301 redirection rules?
- Changes done to .htaccess are not getting reverted back
- How to change search url produced by ‘s GET method?
- Need help with regex
- Using .htaccess to redirect /da/ to / in URL
- Standard Regex syntax doesn’t work in WordPress rewrite rule
- How to combine nearly identical custom rewrite rules for WordPress
- Masking wp-content/themes/name/images to just images directory using htaccess
- Using custom/dynamic “slug” for a page
- Disable wordpress pagination URL rewrite for specific page
- How to use Post Custom Metadata in Post Titles and Post Permalinks
- Using WordPress with Apache behind an nginx reverse proxy
- How do i change the search permanent links
- WordPress Network on IIS7/SQL Server – Rewrite Issues
- Custom comments
- Is there a way to create alias without using htacess, permalinks or delving into code?
- hard flush_rewrite_rules() not regenerating .htaccess
- Rewrite Rules Are Redirecting and Not Passing VARs
- Adding rewrite rules directly to .htaccess file
- Regex expression for redirecting image URLs to another folder
- I want to add a new tag to WordPress URL permastruct
- rewrite wordpress page url for seo friendly query strings
- Best way to trigger rewrite rules
- WordPress Rewrite rule is not working
- Custom taxonomy terms as children of multiple custom post types
- Rewrite dynamic URLs as pretty URLs in WordPress functions.php (add_rewrite_rule) – what’s wrong with my code?
- WordPress index in subdirectory, blogposts in root directory
- How to use a RewriteRule to change endpoint url
- I want to add one extra field to my URLs, I’m using Rewrite functions but it doesn’t work
- .htaccess RewriteRule to include post type and taxonomy
- Stop wordpress to redirecting home page if no page found
- Additional .htaccess rules based on wp page
- Regex for pdf’s – Old .asp Site folder structure to new WordPress Media Folder(s)