Forum Moderators: phranque

Message Too Old, No Replies

Direct Link Image

Problems Doing So

         

iGeek

4:47 am on Mar 28, 2007 (gmt 0)

10+ Year Member



Hello everyone,

I'm new to some advanced .htaccess stuff, so bear with me.

I currently have this is my .htaccess file:


Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

...which obviously adds "www." to my URL if not done so already. So, since I did that, my code to block images from being direct linked is this:

RewriteCond %{HTTP_REFERER} !^http://(www\.)?example.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .*\.(jpe?g¦gif¦bmp¦png)$ - [F]

Works great. However, I have two subdomains, "www.gallery.example.com" and "www.forum.example.com" that both are being blocked from displaying images. How do I fix this?

Thanks,
Steven

[edited by: jdMorgan at 4:52 am (utc) on Mar. 28, 2007]
[edit reason] Example.com. Please see TOS. [/edit]

jdMorgan

5:04 am on Mar 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Simply include the forum and gallery sub-subdomains in the "allowed" referrer URL:

Options +FollowSymlinks
RewriteEngine on
#
RewriteCond %{HTTP_HOST} !^www\. [b][NC][/b]
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]
#
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !^http://[b]www\.(forum\.¦gallery\.)?example\.com[/b]
RewriteRule [b]\.(jp[/b]e?g¦gif¦bmp¦png)$ - [F]

A few tidy-ups and speed-ups in there as well...

You might consider getting rid of the redundant "www" subdomain level for "forum" and "gallery" -- It would be perfectly-acceptable, and even preferable from a technical standpoint (and shorter), to use www.example.com, forum.example.com, and gallery.example.com.

Replace all broken pipe "¦" characters above with solid pipe characters before use; Posting on this board modifies the pipe characters.

Jim

iGeek

5:15 am on Mar 28, 2007 (gmt 0)

10+ Year Member



Sorry about the links, I copy and pasted the code then just typed it out. Won't happen again.

Anyways, thanks for the code. I'm uploading it right now!