.htaccess help please

Discussions about Apache mod Rewrite, .htaccess, Use, experiences ... URL Rewriting.

Moderator: Moderators

.htaccess help please

Postby chez » Sun Sep 13, 2009 1:45 am

I want to prevent hotlinking of images and media on my site.

I would like it so that any hotlinked files are simply not displayed, any directly linked files (with referrer info) result in the user being redirected to my home page and any cases with blank referrer info resulting in the image being displayed.

I want to allow display of images on my own domain (www.ohlookaforum.com) and on a couple of my blogs (ohlookaforum.blogspot.com and ohlookaforum.wordpress.com)

Is this code correct? -

Code: Select all
Options -Indexes
Options +FollowSymLinks

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} .*jpg$|.*gif$|.*png$|.*mp3$|.*wav$|.*swf$|.*mp4$|.*mpg$|.*flv$|.*avi$|.*bmp$|.*jpeg$|.*mpeg$ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !ohlookaforum\.com [NC]
RewriteCond %{HTTP_REFERER} !ohlookaforum\.blogspot\.com [NC]
RewriteCond %{HTTP_REFERER} !ohlookaforum\.wordpress\.com [NC]
RewriteCond %{HTTP_REFERER} !google\. [NC]
RewriteCond %{HTTP_REFERER} !yahoo\. [NC]
RewriteCond %{HTTP_REFERER} !search\?q=cache [NC]
RewriteRule (.*) /index.php



Assuming it is, is this the correct way to implement it with my phpBB SEO rewrite rules? -

Code: Select all
# Lines That should already be in your .htacess
<Files "config.php">
   Order Allow,Deny
   Deny from All
</Files>
<Files "common.php">
   Order Allow,Deny
   Deny from All
</Files>

# You may need to un-comment the following lines
  Options +FollowSymlinks
  Options -Indexes
# To make sure that rewritten dir or file (/|.html) will not load dir.php in case it exist
# Options -MultiViews
# REMEBER YOU ONLY NEED TO STARD MOD REWRITE ONCE
RewriteEngine On
# REWRITE BASE
RewriteBase /
# HERE IS A GOOD PLACE TO FORCE CANONICAL DOMAIN
# RewriteCond %{HTTP_HOST} !^localhost$ [NC]
# RewriteRule ^(.*)$ http://localhost/$1 [QSA,L,R=301]

# DO NOT GO FURTHER IF THE REQUESTED FILE / DIR DOES EXISTS
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . - [L]

RewriteCond %{REQUEST_FILENAME} .*jpg$|.*gif$|.*png$|.*mp3$|.*wav$|.*swf$|.*mp4$|.*mpg$|.*flv$|.*avi$|.*bmp$|.*jpeg$|.*mpeg$ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !ohlookaforum\.com [NC]
RewriteCond %{HTTP_REFERER} !ohlookaforum\.blogspot\.com [NC]
RewriteCond %{HTTP_REFERER} !ohlookaforum\.wordpress\.com [NC]
RewriteCond %{HTTP_REFERER} !google\. [NC]
RewriteCond %{HTTP_REFERER} !yahoo\. [NC]
RewriteCond %{HTTP_REFERER} !search\?q=cache [NC]
RewriteRule (.*) /index.php

#####################################################
# PHPBB SEO REWRITE RULES ALL MODES
#####################################################

(everything below this won't be changed and works perfectly now)


Thank you in advance for your help.

Chez
chez
 
Posts: 37
Joined: Sun May 24, 2009 10:08 am

Advertisement

Re: .htaccess help please

Postby chez » Mon Sep 14, 2009 4:19 am

I'd really appreciate any help with this.. I'm not very clued up when it comes to mod rewrite and htaccess and I'd like to stop people from hotlinking from my site.

Thanks
Chez
chez
 
Posts: 37
Joined: Sun May 24, 2009 10:08 am

Re: .htaccess help please

Postby iwanttobelieve » Tue Sep 15, 2009 1:21 pm

Have you tested your solution? You should have [NC,L] after "RewriteRule (.*) /index.php".
iwanttobelieve
PR1
PR1
 
Posts: 123
Joined: Sun Jun 14, 2009 5:37 am
Location: Somewhere I don't belong lol

Re: .htaccess help please

Postby chez » Tue Sep 15, 2009 10:13 pm

iwanttobelieve wrote:Have you tested your solution? You should have [NC,L] after "RewriteRule (.*) /index.php".


Thanks for the reply. I haven't tested yet, as I was very wary of breaking the URL rewriting on my site and messing it up for my visitors.

I will add the [NC,L] and give it a try tomorrow.
chez
 
Posts: 37
Joined: Sun May 24, 2009 10:08 am

Re: .htaccess help please

Postby iwanttobelieve » Wed Sep 16, 2009 4:09 am

You don't have a test server? It's quite common for a webmaster to have one so you don't have to worry about wrong changes affecting your live website.
iwanttobelieve
PR1
PR1
 
Posts: 123
Joined: Sun Jun 14, 2009 5:37 am
Location: Somewhere I don't belong lol

Re: .htaccess help please

Postby chez » Wed Sep 16, 2009 5:26 pm

I did have xampp installed, but my laptop had to be restored, so no.
chez
 
Posts: 37
Joined: Sun May 24, 2009 10:08 am

Re: .htaccess help please

Postby dcz » Sun Sep 27, 2009 1:51 pm

Come on, xampp does not even need to be installed to run ;)

Anyway for the location, you should place them before :
Code: Select all
# DO NOT GO FURTHER IF THE REQUESTED FILE / DIR DOES EXISTS
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . - [L]


Then, your code looks correct, even though I would rather use :
Code: Select all
RewriteCond %{REQUEST_FILENAME} \.(jpe?g|gif|png|mp3|wav|swf|mp4|mpg|flv|avi|bmp|mpeg)$ [NC]

instead of :
Code: Select all
RewriteCond %{REQUEST_FILENAME} .*jpg$|.*gif$|.*png$|.*mp3$|.*wav$|.*swf$|.*mp4$|.*mpg$|.*flv$|.*avi$|.*bmp$|.*jpeg$|.*mpeg$ [NC]


Does the same job in a bit more efficient way.

++
Useful links :
SEO Forum || SEO Directory || SEO phpBB || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Recherche
dcz
Admin
Admin
 
Posts: 21219
Joined: Fri Apr 28, 2006 9:03 pm


Return to Apache mod Rewrite

 


  • Related topics
    Replies
    Views
    Last post

Who is online

Users browsing this forum: No registered users and 3 guests