.htaccess issues

This is a discussion on .htaccess issues within the Apache Web Server forums, part of the Web Server and Related Forums category; I'm having some real issues with .htaccess file. I'm trying to disable hotlinking, which I've been able ...


Go Back   Usenet Forums > Web Server and Related Forums > Apache Web Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 11-08-2006
d362636@yahoo.com
 
Posts: n/a
Default .htaccess issues

I'm having some real issues with .htaccess file. I'm trying to disable
hotlinking, which I've been able to do, but I'm also trying to allow it
from my forums(and InvisionFree forum) and that's what's throwing me. I
didn't write what I am about to post, it was generated by the last
hosting service I had, I just sort of took the file when I moved to my
new hosting service and it seems to work(except for letting me directly
link to pics from the forum):

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER}
!^http://s4.invisionfree.com/myforum/index.php/.*$ [NC]
RewriteCond %{HTTP_REFERER}
!^http://s4.invisionfree.com/myforum/index.php$ [NC]
RewriteCond %{HTTP_REFERER} !^http://mydomain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://mydomain.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.mydomain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.mydomain.com$ [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ http://www.mydomain.com [R,NC]

Of course, the "myforum, mydomain" things are just representing my
actual domain and InvisionFree board.

Does this look odd to anyone? Other .htaccess files doing this don't
seem to have everything listed twice, just slightly different on the
very end of the url.

Now, like I said, this file already allows me to disable hotlinking
from other sites, so I'm good there, it just won't seem to allow me to
do *any* linking from my forum. Another weird thing, my forum, when you
hit the front page it shows up as:

http://s4.invisionfree.com/myforum/index.php/

But when you go to any area, or even back to the forum index after
going into another area, it changes to this:

http://z4.invisionfree.com/myforum/index.php/
(the s changes to a z)

I've tried adding the "z" url to the htaccess file as well, no luck.
The only thing I can get to work is adding the direct url(of the forum
post) to the htaccess file, but that really sucks to have to add the
url everytime someone makes a post that links to an image on the site.
:(

If anyone has any suggestions, I'd really, really, really appreciate
it. This is something I've tried to get working for what seems likes
months on end, and never with any luck. If any further info is needed,
just let me know, I can provide you with as much as I can find. :)

DM

  #2 (permalink)  
Old 11-08-2006
HansH
 
Posts: n/a
Default Re: .htaccess issues

<d362636@yahoo.com> schreef in bericht
news:1163019828.895883.209370@m7g2000cwm.googlegro ups.com...
> RewriteEngine on
> RewriteCond %{HTTP_REFERER} !^$
> RewriteCond %{HTTP_REFERER}
> !^http://s4.invisionfree.com/myforum/index.php/.*$ [NC]
> RewriteCond %{HTTP_REFERER}
> !^http://s4.invisionfree.com/myforum/index.php$ [NC]
> RewriteCond %{HTTP_REFERER} !^http://mydomain.com/.*$ [NC]
> RewriteCond %{HTTP_REFERER} !^http://mydomain.com$ [NC]
> RewriteCond %{HTTP_REFERER} !^http://www.mydomain.com/.*$ [NC]
> RewriteCond %{HTTP_REFERER} !^http://www.mydomain.com$ [NC]
> RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ http://www.mydomain.com [R,NC]
>
> Of course, the "myforum, mydomain" things are just representing my
> actual domain and InvisionFree board.
>
> Does this look odd to anyone? Other .htaccess files doing this don't
> seem to have everything listed twice, just slightly different on the
> very end of the url.

Right, by using the $ at the end the FULL url is cheched, the preseding .*
is a regex wildcard meaning any charachet ero or more times
So
RewriteCond %{HTTP_REFERER} !^http://mydomain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://mydomain.com$ [NC]
can be shortened to
RewriteCond %{HTTP_REFERER} !^http://mydomain\.com [NC]
making it test the beginning og Urls only
Note thr \ before .: this way the dot is not a any-character wildcard, but a
literal dot.

> Now, like I said, this file already allows me to disable hotlinking
> from other sites, so I'm good there, it just won't seem to allow me to
> do *any* linking from my forum.

Your domain may have a prefix like in www.mydomain.com
let's prefix that part
RewriteCond %{HTTP_REFERER} !^http://([^\.]+\.)?mydomain\.com [NC]

> Another weird thing, my forum, when you
> hit the front page it shows up as:
> http://s4.invisionfree.com/myforum/index.php/
>
> But when you go to any area, or even back to the forum index after
> going into another area, it changes to this:
>
> http://z4.invisionfree.com/myforum/index.php/
> (the s changes to a z)

Probably some loadbalacing, just regex this prefix -and drop the full match-
too
RewriteCond %{HTTP_REFERER} !^http://([^\.]+\.)?invisionfree\.com/myforum/
[NC]


All in all try these untested lines
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://([^\.]+\.)?invisionfree\.com/myforum/
[NC]
RewriteCond %{HTTP_REFERER} !^http://([^\.]+\.)?mydomain\.com [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ - [F]


HansH


  #3 (permalink)  
Old 11-09-2006
BelPowerslave
 
Posts: n/a
Default Re: .htaccess issues

> All in all try these untested lines
> RewriteEngine on
> RewriteCond %{HTTP_REFERER} !^$
> RewriteCond %{HTTP_REFERER} !^http://([^\.]+\.)?invisionfree\.com/myforum/
> [NC]
> RewriteCond %{HTTP_REFERER} !^http://([^\.]+\.)?mydomain\.com [NC]
> RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ - [F]


Very interesting, I had no idea on all the wildcard stuff. I tried the
above lines and still no luck, unfortunately, on getting the server to
allow direct linking to pics from the forums. This time around though,
rather than just shoot me to the front page it gave me a "Server Error"
page(just that generic one you get). I think we may be getting closer.
I'll play around with it a bit more, see if I can catch any luck.
Again, I appreciate your help and especially the info! :)

Thanks,

DM

  #4 (permalink)  
Old 11-09-2006
rh
 
Posts: n/a
Default Re: .htaccess issues

"BelPowerslave" <bel@whipassgaming.com> wrote in message
news:1163034625.934977.248730@m73g2000cwd.googlegr oups.com...

<snip HansH solution>

> Very interesting, I had no idea on all the wildcard stuff. I tried the
> above lines and still no luck, unfortunately, on getting the server to
> allow direct linking to pics from the forums. This time around though,
> rather than just shoot me to the front page it gave me a "Server Error"
> page(just that generic one you get). I think we may be getting closer.
> I'll play around with it a bit more, see if I can catch any luck.
> Again, I appreciate your help and especially the info! :)
>
> Thanks,
>
> DM
>


The solution provided by HansH should work.

If you copied and pasted the solution make certain that any wrapped lines
are corrected. The [NC] should be on the end of the line before it not on it's
own line as it is in Hans Post. The server error (500?) probably means there
is a syntax error in the .htaccess file and I would bet that's it.

HansH's solution "unwrapped"

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://([^\.]+\.)?invisionfree\.com/myforum/ [NC]
RewriteCond %{HTTP_REFERER} !^http://([^\.]+\.)?mydomain\.com [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ - [F]


With domain names substituted, this works fine on my test server.

Note that you may have problems with some proxies that give incorrect
http_referer info. If any of your users have problems viewing images, I'd
check that first.

Rich


  #5 (permalink)  
Old 11-09-2006
d362636@yahoo.com
 
Posts: n/a
Default Re: .htaccess issues

> The solution provided by HansH should work.
>
> If you copied and pasted the solution make certain that any wrapped lines
> are corrected. The [NC] should be on the end of the line before it not on it's
> own line as it is in Hans Post. The server error (500?) probably means there
> is a syntax error in the .htaccess file and I would bet that's it.
>
> HansH's solution "unwrapped"
>
> RewriteEngine on
> RewriteCond %{HTTP_REFERER} !^$
> RewriteCond %{HTTP_REFERER} !^http://([^\.]+\.)?invisionfree\.com/myforum/ [NC]
> RewriteCond %{HTTP_REFERER} !^http://([^\.]+\.)?mydomain\.com [NC]
> RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ - [F]
>
>
> With domain names substituted, this works fine on my test server.
>
> Note that you may have problems with some proxies that give incorrect
> http_referer info. If any of your users have problems viewing images, I'd
> check that first.


Ah, there it is. I'm such an idiot, I missed that and just left it
there on its own line! Argh! Yeah, this works for the forums now,
thanks so much to both of you guys!!! I was wanting to make one
modification and I thought I'd run it past you two and see if you think
it'll fly. Right now, anyone trying to hotlink something gets a server
error page(generic), but before(with the old .htaccess file) it'd send
them to the front page of the site. I was thinking it had to do with
the final line of the file:

(original line)
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ http://www.mydomain.com [R,NC]

This is the line that tells it to redirect people coming from direct
links to files(or hotlinking) to the front page right? If I modified
the lines you and Hans gave me to enable this again, would it look like
this?

RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ http://www.mydomain.com - [F]

Or is it something more complicated that I am probably mpt going to
understand? :)

Thanks again so much for your help, both of you!

DM

BTW, sorry about any confusion on my replies, I was using another guy's
computer at work and I didn't realize he was still logged in(bel).

  #6 (permalink)  
Old 11-09-2006
HansH
 
Posts: n/a
Default Re: .htaccess issues

<d362636@yahoo.com> schreef in bericht
news:1163060221.050797.251630@i42g2000cwa.googlegr oups.com...
> This is the line that tells it to redirect people coming from direct
> links to files(or hotlinking) to the front page right? If I modified
> the lines you and Hans gave me to enable this again, would it
> look like this?
>
> RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ http://www.mydomain.com - [F]

Should have commented that change ...
.... the dash is a placeholder and implies the url is passed unchanged.
The passed url is irrelevant for a blunt 403 anyway.

AFAIK no browser is to display _html_ when expecting an _image_.

Even better -keeps your error_log clean too- might be
RewriteRule .*\.(jpe?g|gif|png|bmp)$ http://www.mydomain.com/nfyen.$1
Note yet another regex tweak making the e in jpeg optional, thus matching
jpg too
(Ofcourse, this requires a valid image file named nfyen -not fot your eyes
now ;-)- for each extention listed)


HansH



  #7 (permalink)  
Old 11-09-2006
d362636@yahoo.com
 
Posts: n/a
Default Re: .htaccess issues

> > RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ http://www.mydomain.com - [F]
> Should have commented that change ...
> ... the dash is a placeholder and implies the url is passed unchanged.
> The passed url is irrelevant for a blunt 403 anyway.
>
> AFAIK no browser is to display _html_ when expecting an _image_.
>
> Even better -keeps your error_log clean too- might be
> RewriteRule .*\.(jpe?g|gif|png|bmp)$ http://www.mydomain.com/nfyen.$1
> Note yet another regex tweak making the e in jpeg optional, thus matching
> jpg too
> (Ofcourse, this requires a valid image file named nfyen -not fot your eyes
> now ;-)- for each extention listed)
>
>
> HansH


This is working flawlessly, thank you sooooo much for you help, both of
you! I'd never of figured this stuff out, ever. :)

Thanks again, I really do appreciate it!

DM

  #8 (permalink)  
Old 12-17-2006
Aceata
 
Posts: n/a
Default Re: .htaccess issues

Does this mean you can use .htaccess on GPC?

  #9 (permalink)  
Old 12-17-2006
HansH
 
Posts: n/a
Default Re: .htaccess issues

"Aceata" <q.aceata@gmail.com> schreef in bericht
news:1166331779.893163.73990@t46g2000cwa.googlegro ups.com...
> Does this mean you can use .htaccess on GPC?
>

To improve reading for those NOT using a webfront it is common to leave a
few lines of the previous message. Continuing an issue after 5 weeks may
need more details ... or a fresh start.

What's GPC ...
.... Georgia Perimeter Collega
.... Grain Processing Corporation
.... Graphics Performance Characterization
.... Grid and Pervasive Computing
.... Gel Permeatie Chromatografie

HansH


 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 10:48 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0