Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RewriteCond

Status
Not open for further replies.

DonP

IS-IT--Management
Jul 20, 2000
684
US
I've read everything I can find on the subject but can't get this to work properly. I'm trying to block the direct linking of my images from outside the sites. It blocks some, but not all, images even when loaded through one of the domains listed. I tried adding "php" to the list as some images use a php file to load them. Any ideas?

Code:
RewriteEngine on
RewriteCond !%{HTTP_REFERER} !^$
RewriteCond !%{HTTP_REFERER} !^[URL unfurl="true"]http://localhost\:8080*$[/URL] [NC,OR]
RewriteCond !%{HTTP_REFERER} ^[URL unfurl="true"]http://(www\.)?domain.com/.*$[/URL] [NC,OR]
RewriteCond !%{HTTP_REFERER} ^[URL unfurl="true"]http://(www\.)?domain.net/.*$[/URL] [NC,OR]
RewriteCond !%{HTTP_REFERER} ^[URL unfurl="true"]http://(www\.)?domain.org/.*$[/URL] [NC]
RewriteRule \.(php|gif|jpe?g|png|wav|mpg|mp3|swd|swf)$ [URL unfurl="true"]http://www.domain.com/images/system_images/nolinks.jpg[/URL] [R,NC,L]

Also, the above seems to crash when used with:

Code:
Options -Indexes Includes

but does not crash when I remove "Includes". I don't need Includes but I am curious why it causes the problem.

Don
Experienced in HTML, Perl, PHP, VBScript, PWS, IIS and Apache and MS-Access, MS-SQL, MySQL databases
 
Hi

I have no working Apache handy, so just one strange thing I see there. When negate a match, you have to put the exclamation mark ( ! ) only before the pattern.
Code:
RewriteCond %{HTTP_REFERER} !^$
But anyway, do not expect to much from this method. Is easy to fake the HTTP_REFERER.

Feherke.
 
Oops! That was an error in the posting. I had taken out the ! temporarily and put it back in the wrong place when I posted it. This is actually what it has:

Code:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^[URL unfurl="true"]http://localhost\:8080*$[/URL] [NC,OR]
RewriteCond %{HTTP_REFERER} !^[URL unfurl="true"]http://(www\.)?domain.com/.*$[/URL] [NC,OR]
RewriteCond %{HTTP_REFERER} !^[URL unfurl="true"]http://(www\.)?domain.net/.*$[/URL] [NC,OR]
RewriteCond %{HTTP_REFERER} !^[URL unfurl="true"]http://(www\.)?domain.org/.*$[/URL] [NC]
RewriteRule \.(php|gif|jpe?g|png|wav|mpg|mp3|swd|swf)$ [URL unfurl="true"]http://www.domain.com/images/system_images/nolinks.jpg[/URL] [R,NC,L]

Thanks for pointing it out. No, I don't expect a lot from it. It's for a fan site of a '50s singer so I just want to minimize others from direct linking to the images.

It seems to behave differently on my development system, which has Apache2, than it does on the live server, which has an older Apache. It's not clear if this is due to the different version of Apache or to the port my local copy uses. I wasn't sure if I needed to include it as part of the RewriteCond or not.

Some examples I found showed the dot escaped while others did not. Should it be domain\.com or not?

Don
Experienced in HTML, Perl, PHP, VBScript, PWS, IIS and Apache and MS-Access, MS-SQL, MySQL databases
 
Hi

Yes, while that is a regular expression and dot ( . ) is metacharacter, you must escape it, to work as expected.

About the version incompatibilities, I noticed them myself too. But did not found any documentation of those changed behaviours, so finally I gave it up and not used [tt]mod_rewrite[/tt].

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top