Mobile app version of vmapp.org
Login or Join
Margaret670

: .htaccess rewrite wildcard folder paths from host My desired result is change a file to root / from a N number of paths. For example: www.host.com/a/b/c/e/f/g/images/1.jpg, where A~G is not always

@Margaret670

Posted in: #Htaccess #ModRewrite

My desired result is change a file to root / from a N number of paths.

For example: host.com/a/b/c/e/f/g/images/1.jpg, where A~G is not always given. Result: host.com/images/1.jpg.
This is what I have so far: host.com/a/images --> host.com/images using: RewriteRule ^a/images/$ images/ [L].

What I need is a wildcard in front of /images/ like this: RewriteRule ^*/images/$ images/ [L].

How can I do this correctly in .htaccess?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Margaret670

1 Comments

Sorted by latest first Latest Oldest Best

 

@Yeniel560

This should do the trick: RewriteRule ^.+/images/$ images/ [L]

In regex, the .+ is a wildcard matching at least one character, so it will match
host.com/**a**/images and host.com/**a/b**/images but not host.com/images.
When working with regular expressions for pattern matching, I have always found this page helpful: regular-expressions.info/.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme