Forum Moderators: phranque

Message Too Old, No Replies

Advanced .htaccess

         

eeos

7:10 pm on Sep 29, 2005 (gmt 0)

10+ Year Member



I find it interesting how little (understandable) information I can find regarding the .htaccess file, but here's my dilemma:

I want to dissalow direct linking from a particular folder. That's easy enough, but what I want to do is if someone is requesting the image bush.jpg -- I want to send them to www.url.com/show.php?=bush.jpg.

I know you can use wild cards in .htaccess, but I have been unable to figure this out. Any help would be much appreciated, Thank you.

eeos

8:55 pm on Sep 29, 2005 (gmt 0)

10+ Year Member



Alright, so I've done a lot of searching and I found a solution on a list apart. I'm having an issue though.

My .htaccess file is as follows:


RewriteEngine On

RewriteCond %{REQUEST_FILENAME} .*jpg$¦.*jpeg$¦.*gif$¦.*png$ [NC]
RewriteCond %{HTTP_REFERER} !example\.net [NC]
RewriteCond %{HTTP_REFERER} !greg\.com [NC]
RewriteCond %{HTTP_REFERER} !google\. [NC]
RewriteCond %{HTTP_REFERER} !search\?q=cache [NC]

RewriteRule (.*) /img.php?img=$1

Now, if I go to http://www.example.net/img/_full/Bluehills.jpg I am indeed fed the page from http://www.example.net/img.php?img=Bluehills.jpg.

When I view the page though, all formatting is lost. It does not load my style sheet, favicon etc.

Someone please help a noob?

[edited by: jdMorgan at 12:48 am (utc) on Sep. 30, 2005]
[edit reason] Examplified URLs & de-linked [/edit]

eeos

9:57 pm on Sep 29, 2005 (gmt 0)

10+ Year Member



Well, I figured out the obvious regarding relative paths and mod_rewrite. Thanks for the help.. erm.. me.

jdMorgan

12:55 am on Sep 30, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



eeos,

Welcome to WebmasterWorld!

This is not a busy forum, so please be patient for replies. :)

Here's a clean-up of your code. It also makes provisions for users behind caching proxies, such as AOL and many corporate networks by allowing for blank referrers:


RewriteEngine On
#
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !example\.net [NC]
RewriteCond %{HTTP_REFERER} !greg-j\.com [NC]
RewriteCond %{HTTP_REFERER} !google\. [NC]
RewriteCond %{HTTP_REFERER} !search\?q=cache [NC]
RewriteRule ^([^.]+\.(jpe?g¦gif¦png))$ /img.php?img=$1 [NC,L]

Change the broken pipe "¦" characters to solid pipes before use; Posting on this forum modifies them.

Jim