If you don't know how to make an .htaccess file, just open up your text
editor and insert these codes, then save it as .htaccess. I am not
responsible if these scripts don't work on your server and you get some sort
of error. If that happens, just make another .htaccess file that is
completely blank. These are all the scripts I use in my .htaccess files.
Enjoy.
--------------------------------------------------------------------------------
This script is used if you don't want people to be able to browse through a
certain directory.
IndexIgnore *
--------------------------------------------------------------------------------
This script is used so that no one can view your .htaccess script (very
useful!).
<Files .htaccess>
order allow,deny
deny from all
</Files>
--------------------------------------------------------------------------------
This is a script that will allow you to change the location of the index
file.
Redirect /olddirectory/oldfile.html
http://yoursite.com/newdirectory/newfile.html
--------------------------------------------------------------------------------
This is a script that will redirect IP's that you don't want viewing your
site. (I set up an account on geocities for this script so that people would
know they had been blocked and why.)
RewriteEngine on
RewriteCond %{REMOTE_ADDR} 00\.00\.00\.
RewriteRule .* http://www.youralternativedirectory/yourwarningpage.htm [R]
*Remember to change the IP address (00\.00\.00\.) to whatever IP you are
blocking, but keep it in the same format! Also, change the URL to the
directory (not a directory on your site) that you can link to to warn them
that they have been blocked.
--------------------------------------------------------------------------------
To block referrals from a specific domain.
SetEnvIfNoCase Referer "^http://www.thatdomain.com/" BadReferrer
order deny,allow
deny from env=BadReferrer
*Remember to change the URL to the URL you wish to block.
--------------------------------------------------------------------------------
This script will not allow people to direct link your files. (You can change
these files to whatever you wish, but be sure to separate your images into
different directories before you do this if you are planning on direct
linking any of them; a good example is if you have a webcam, you'll still
want people to direct those images, but not images that are in other
directories. If you put this in the main part of your site, it will block
all access to those files, so be sure to put it in sub-directories.) This
script will direct whoever is trying to direct-link your images to another
image that is embarrassing.
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourdomain.com/.*$ [NC]
RewriteRule \.(jpg|gif|js|css)$
http://www.yourdomain.com//images/youralternativeimage.jpg [R,L]
--------------------------------------------------------------------------------
You can use this if you don't want to let people direct link your images,
but you don't want to insert an embarrassing image.
RewriteEngine on RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER}
!^http://(www\.)?yourdomain.com/.*$ [NC] RewriteRule \.(gif|jpg)$ - [F]
--------------------------------------------------------------------------------
An example of all these together in an .htaccess file would be:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourdomain.com/.*$ [NC]
RewriteRule \.(jpg|gif|js|css)$
http://www.yourdomain.com//images/youralternativeimage.jpg [R,L]
SetEnvIfNoCase Referer "^http://www.thatdomain.com/" BadReferrer
order deny,allow
deny from env=BadReferrer
IndexIgnore *
--------------------------------------------------------------------------------
Just remember to double-space between the scripts and everything should work
fine. If some of these scripts just don't work for you, go to Google.Com and
look up .htaccess scripts because there are many ways to do one thing in
.htaccess and not all servers accept the same scripts.