开发者

How do I hide actual directories using mod_rewrite?

开发者 https://www.devze.com 2023-01-15 21:41 出处:网络
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.

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:开发者_JAVA百科//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?


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]
0

精彩评论

暂无评论...
验证码 换一张
取 消