views:

20

answers:

1

I am hosting a couple of domains of the same wordpress installation, now I'd like to have a per-domain folder for some various files I need to put up there.

Essentially I want to map like this:

URL                     Path
webbfarbror.se/f/*      _files/webbfarbror.se/*
grapefrukt.com/f/*      _files/grapefrukt.com/*

This little snippet does the job nicely and the RewriteCond let's me enable and disable this on a per domain basis.

ReWriteCond %{HTTP_HOST} webbfarbror.se
ReWriteRule ^f/(.*)$ _files/%{HTTP_HOST}/$1 [L]

However, a file at say, http://grapefrukt.com/f/awesome.jpg is also accessible at it's "real" URL http://grapefrukt.com/_files/grapefrukt.com/awesome.jpg

All my attempts result in infinite redirects back and forth.

How do I disable access through the latter URL?

+1  A: 

You can examine the original request as it was sent to the server, which is available as %{THE_REQUEST}. Checking for the /_files/ prefix indicates that the request was of the latter type, and you can then redirect to the appropriate format:

RewriteCond %{THE_REQUEST} ^[A-Z]+\s/_files/
RewriteRule ^_files/[^/]+/(.*)$ http://%{HTTP_HOST}/f/$1 [R=301,L]
Tim Stone
This sort of works, but for some reason it won't match subfolders such as: http://grapefrukt.com/_files/grapefrukt.com/games/
grapefrukt
@grapefrukt - Hmm, it seems to work alright on my test server. Is there a `.htaccess` with `mod_rewrite` directives in that directory maybe?
Tim Stone
turns out this does indeed work, i suspect there was some kind of caching of the rewrites going on on my host. thanks!
grapefrukt