Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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

I need a Rewrite Rule for apache to rewrite urls like:


So, I need to remove all / parts between the "archives" and the last /, preserving the part before the / and after the /.

share|improve this question
up vote 2 down vote accepted

Something like this should do what you want:

RewriteRule ^(/~dun3/archives/).+?/([^/]+/[^/]+)$ $1$2 [L,R=301]

(The final R=301 part sends a HTTP 301 Moved Permanently header, which I presume is what you want to do, but if not you can simply omit that part.)

share|improve this answer
Cool, that's exactly what I needed. Thanks. – Tobias Hertkorn May 11 '09 at 12:40
RewriteRule ^(.*?)/(.*?)/.*/(.*?)/(.*?)$ $1/$2/$3/$4
share|improve this answer

Your Answer


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.