Hotlinking not working on new server.

dave_mck
dave_mck's picture

Joined: 2006-09-01
Posts: 11
Posted: Fri, 2010-12-10 17:14

Just got my new server up and a fresh copy of Gallery2 on it. (Gallery version = 2.3.1 core 1.3.0.1 )

I can't seem to get the hotlink protection to work and can't see what I'm doing wrong so I'll post it here.

I'm running WAMP 2.0 (Webserver = Apache/2.2.11 (Win32) PHP/5.3.0
It's a multi site setup. mckittricks.org/gallery2 <- core // mckittricks.org/test <- gallery

Quote:
htaccess file located in mckittricks.org/test

# BEGIN Url Rewrite section
# (Automatically generated. Do not edit this section)
<IfModule mod_rewrite.c>
RewriteEngine On

RewriteBase /test/

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} gallery\_remote2\.php
RewriteCond %{REQUEST_URI} !/test/main\.php$
RewriteRule . - [L]

RewriteCond %{QUERY_STRING} view=core.DownloadItem
RewriteCond %{HTTP:Referer} !^[a-zA-Z0-9\+\.\-]+://www.mckittricks.org/ [NC]
RewriteCond %{HTTP:Referer} !^$
RewriteRule . /test/main.php [F,L]
RewriteCond %{QUERY_STRING} g2_view=core.DownloadItem
RewriteCond %{QUERY_STRING} g2_itemId=([0-9]+)
RewriteCond %{HTTP:Referer} !^[a-zA-Z0-9\+\.\-]+://www.mckittricks.org/ [NC]
RewriteCond %{HTTP:Referer} !^$
RewriteRule . /test/main.php?g2_view=rewrite.DownloadItem&g2_itemId=%1 [L]
RewriteCond %{THE_REQUEST} /test/v/(\?.|\ .)
RewriteCond %{REQUEST_URI} !/test/main\.php$
RewriteRule . /test/main.php [QSA,L]
RewriteCond %{THE_REQUEST} /test/d/([0-9]+)\-([0-9]+)/([^/?]+)(\?.|\ .)
RewriteCond %{REQUEST_URI} !/test/main\.php$
RewriteRule . /test/main.php?g2_view=core.DownloadItem&g2_itemId=%1&g2_serialNumber=%2&g2_fileName=%3 [QSA,L]
</IfModule>

# END Url Rewrite section

Quote:
httpd.conf has the following:
<Directory e:\web\test\>
AllowOverride FileInfo Options
</Directory>

 
dave_mck
dave_mck's picture

Joined: 2006-09-01
Posts: 11
Posted: Sat, 2010-12-11 02:21

Just to add, I also get this quite often. Not sure if it's related.
I've searched around here and Google but can't find any answer to why I keep getting these errors.

Quote:
[Fri Dec 10 20:49:47 2010] [error] [client 66.249.71.34] PHP Warning: Invalid argument supplied for foreach() in E:\\Web\\gallery2\\modules\\rewrite\\classes\\parsers\\pathinfo\\PathInfoUrlGenerator.class on line 105
[Fri Dec 10 20:49:47 2010] [error] [client 66.249.71.34] PHP Warning: Cannot modify header information - headers already sent by (output started at E:\\Web\\gallery2\\modules\\rewrite\\classes\\parsers\\pathinfo\\PathInfoUrlGenerator.class:105) in E:\\Web\\gallery2\\modules\\core\\classes\\GalleryPhpVm.class on line 142

 
dave_mck
dave_mck's picture

Joined: 2006-09-01
Posts: 11
Posted: Sun, 2010-12-12 02:50

Well, after a day, I came back to the forum and searched again and tried a few things.
Finally getting something to work. YEA!!!

For some reason the built in option to block hot linking dosn't seem to work but I found a way by mixing some code from this topic:
http://gallery.menalto.com/node/8329

Having this in my httpd.conf dosn't seem to matter so I got rid of it:

Quote:
<Directory e:\web\test\>
AllowOverride FileInfo Options
</Directory>

Haven't had any PHP errors today but I haven't been mass uploading thousands of images today either. My production site has 14000 images in it. All uploaded over a full day.
http://www.sportsonephoto.com/gallery/

So, here is my .htaccess file.

Quote:
# BEGIN Url Rewrite section
# (Automatically generated. Do not edit this section)
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On

RewriteBase /test/

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} gallery\_remote2\.php
RewriteCond %{REQUEST_URI} !/test/main\.php$
RewriteRule . - [L]

RewriteCond %{HTTP_REFERER} !^http://(.+)?mckittricks.org [NC]
RewriteRule [^/]+.(gif|jpg|GIF|JPG)$ nohotlink.gif [R,L]

RewriteCond %{THE_REQUEST} /test/v/(\?.|\ .)
RewriteCond %{REQUEST_URI} !/test/main\.php$
RewriteRule . /test/main.php [QSA,L]
RewriteCond %{THE_REQUEST} /test/d/([^/?]+)(\?.|\ .)
RewriteCond %{REQUEST_URI} !/test/main\.php$
RewriteRule . /test/main.php?g2_view=core.DownloadItem&g2_fileName=%1 [QSA,L]
</IfModule>

# END Url Rewrite section