Welcome to WebmasterWorld Guest from 54.226.23.160

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

Possible to set virtual directory over top of physical directory?

Mod_Rewrite aliasing

     
7:21 am on Aug 13, 2011 (gmt 0)

Full Member

10+ Year Member

joined:Oct 9, 2007
posts: 295
votes: 0


Is it possible to configure a 'virtual directory' over top of a physical directory of the same path?

For example, if I have a source file at physical path:
/path/picture.jpg

I want to use Mod_Rewrite to point URL
example.com/path/picture.jpg?w=100&h=50
to an image processing script at say /include/image-resizer.php

E.g.:
RewriteCond %{QUERY_STRING} .
RewriteRule ^(.+)\.(jpe?g|png|gif|bmp|pdf)$ /include/image-resizer.php?src=/$1.$2 [NC,QSA,L]


This works if I inject a virtual path in there but not in the above form where it conflicts with the existing physical directory.

Is this possible or will I have to invent a virtual directory to base the paths on?
7:36 am on Aug 13, 2011 (gmt 0)

Full Member

10+ Year Member

joined:Oct 9, 2007
posts: 295
votes: 0


Edit: just realized the above is working, but I have an .htaccess file in the physical /path/ which is blocking access because I don't actually want to permit accessing of the source image.

Is there a way to allow the above to work while disallowing physical access to /path/picture.jpg?
8:23 am on Aug 13, 2011 (gmt 0)

Full Member

10+ Year Member

joined:Oct 9, 2007
posts: 295
votes: 0


Edit 2: had to resort to doing this in the root htaccess.


RewriteCond %{QUERY_STRING} .
RewriteRule ^(.+)\.(jpe?g|png|gif|bmp|pdf)$ /include/phpthumb/phpThumb.php?src=/$1.$2 [NC,QSA,L]
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^path/to/protect/(.+)\.(jpe?g|png|gif|bmp|pdf)$ - [F,L]


For some reason I couldn't put the blocking instructions, the 2nd Cond block, in an htaccess in the relevant dir as a generic copy-and-dump file along the lines of


RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.+)\.(jpe?g|png|gif|bmp|pdf)$ - [F,L]
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members