views:

54

answers:

1

I am trying to figure how to make a .htaccess RewriteRule so a visitor views: site.com/folder

but is served

site.com/f1/f2/f3/folder/index.php

where f1/... is just an arbitrary line of folders.

Have kicked mod_rewrite a little, and got some really weird results, none I was going for though. Any help wrapping my head around this is greatly appreciated.

+1  A: 

I'm not quite sure what you're trying to achieve. This, however, might solve your problem. Basically it translates any query for /folder, /folder/ or /folder/... to /f1/f2/f3/folder/...:

RewriteRule ^folder(/.*)?$ f1/f2/f3/folder$1


EDIT
If you don't care about anything after site.com/folder, this should suffice:

RewriteRule ^folder$ f1/f2/f3/folder/index.php


EDIT #2
Rewriting the root (according to comment by OP):

RewriteRule ^(.*)$ folder1/folder2/$1 [QSA]

There may be other (better?) ways to translate the root, though.

Docs are available on the QSA directive.

jensgram
Your first pattern will also allow `folderfoobar`.
Gumbo
@Gumbo Oops! Edited.
jensgram
I am able to get the first approach to work, but it still requires I have the root 1 folder deep, so the root index ends up at site.com/folder/index.php... Tried edit 2, but that threw 500 Internal Server Error. I have the .htaccess file in the root of the subdomain this lives in, and do not have any .htacess files below it.
tr0y
I'm not sure what I am doing wrong, but this works: Rewriterule ^folder/(.*)$ folder1/folder2/$1This throws a 500 internal server error: Rewriterule ^(.*)$ folder1/folder2/$1as does this:Rewriterule ^(.*)$ folder1/folder2/$1 [QSA]
tr0y
Where is your `.htaccess` located?
jensgram