views:

26

answers:

3

I can only find mod rewrite examples/tutorials for query's, so can someone help me with this.

I would like this

http://website.tld/Folder1/Folder2/Folder3/Folder4/Folder5/File.exten

to be transformed into

http://website.tld/Folder4/File.exten

Folder4 and Folder5 are multiple directories, while Folder 1-3 stay the same. Also File.exten also should be changeable in the rewrite. thanks.

+1  A: 

This should work:

RewriteRule ^(.*)/(.*)$ Folder1/Folder2/Folder3/$1/Folder5/$2 [QSA,NC]
Kau-Boy
If "Folder5" is not always within the rewriting fil path, you can leave it out. The rewrite will then anyways be able to get you to that folder, as long as you use something like "Folder4/Folder5" in the query. Therefore I used (.*) and not ([^/]+) in my regex.
Kau-Boy
+1  A: 

I would use something like this:

RewriteRule ^([^/]+)/([^/]+)$ Folder1/Folder2/Folder3/$1/Folder5/$2 [QSA,NC]

([^/]+) is better since ^(.*)/(.*)$ would match http://website.tld/somedir/somedir2/somedir3/

A: 
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^grab /public/files/download/download.php

this rule would transform this user's URL..

http://mysite/grab?file=my.zip

server-side, into..

http://mysite/public/files/download/download.php?file=my.zip

says here: http://corz.org/serv/tricks/htaccess2.php

Aziz