lucy24 - 4:00 am on Apr 17, 2013 (gmt 0)
Just one directory pair? This is easy. As far as mod_rewrite is concerned, a directory slash is just another character like "a" or "b". Except the one after your domain name, duh. So in a top-level directory it's simply
RewriteRule ^directory1directory2/(.*) http://www.example.com/directory1/directory2/$1 [R=301,L]
or, if you prefer,
RewriteRule ^directory1(directory2/.*) http://www.example.com/directory1/$1 [R=301,L]
If there is stuff before the first directory, just include it in both sides of the rule:
RewriteRule ^starthere/directory1directory2/(.*) http://www.example.com/starthere/directory1/directory2/$1 [R=301,L]
Sure, you could capture and reuse the "starthere/directory1" part too-- but the server would expend more effort keeping the text in memory than it takes to read and write it over again. No point in capturing text if it can only say one thing.
I should have made you do that yourself, but everyone's been asking complicated questions and the people who speak Apache are nowhere to be seen and I'm annoyed with FutureBasic and, and, and...