grapefrukt
grapefrukt

Reputation: 27045

How do I hide actual directories using mod_rewrite?

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?

Upvotes: 0

Views: 448

Answers (1)

Tim Stone
Tim Stone

Reputation: 19169

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]

Upvotes: 1

Related Questions