Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 given. Result: www.host.com/images/1.jpg.

This is what I have so far: www.host.com/a/images --> www.host.com/images using: RewriteRule ^a\/images/$ images/$1 [L].

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

How can I do this correctly in .htaccess?

share|improve this question

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

In regex, the .+ is a wildcard matching at least one character, so it will match

www.host.com/**a**/images and www.host.com/**a/b**/images but not www.host.com/images.

When working with regular expressions for pattern matching, I have always found this page helpful: http://regular-expressions.info/.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.