Press "Enter" to skip to content

fun with htaccess

have you ever wonder one day you were designing your website and not satisfied with it? want to enhanced it a little bit? well, thats where htaccess comes in. here’s some trick you can do, provided that your webhosting, server or whatever support htaccess.

1. “damn the bandwidth stealer. i want them go away.” …erm, someone said to me that once. people hotlinking stuff, mostly images from your website and you don’t want them to do that? you can get rid of them by using htaccess. here’s how.
a) go to the path of your website.
b) edit (if you have the .htaccess file) or create a new file, naming it .htaccess.
c) put this into that file:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www.)?*$ [NC]
RewriteCond %{HTTP_REFERER} !^*$ [NC]
RewriteRule .*[Jj][Pp][Gg]$|.*[Gg][Ii][Ff]$

(remember to change the ip and the url. the “go_away.jpg” file is showed to the bandwidth stealer website when they are trying to hotlinking from your site. change it to your desired image. you can also use a blank page and change the path at RewriteRule.)
d) save the file and upload it into your website.
e) test it & now, hotlinkers begone!

erm, here’s…

2. “my webhosting 404 error page sucks and ugly. i want to change it.” hey hey, relax. you can do it using htaccess. here’s how.
a) edit your .htaccess file.
b) put this script into it:

ErrorDocument 400 /errordoc/404.html
ErrorDocument 401 /errordoc/401.html
ErrorDocument 403
ErrorDocument 404
ErrorDocument 500

(change the path or the url according to your taste.)

3. got some sensitive stuff you kept in a folder? wan’t to restrict them to exclusive people? here’s how.
a) create a .htpasswd file and put your username and password. create it [here]
b) put this in your .htaccess file:

AuthType Basic
AuthName “Secret”
AuthUserFile /path/of/your/.htpasswd
require valid-user

c) save everything and upload everything (e.g: .htaccess & .htpasswd file) in the folder you want to restrict.
d) test it.

4. have a file like this?: want to shorten it? here’s how.
a) put this in your .htaccess file:

Redirect /short.html

5. using IIS webserver (internet information services)? wow, you’re using windows nt :roll:. there are currently several worms exploit problems with IIS server, they search out path problems in IIS that would allow them to run cmd.exe which is the NT dos shell. unfortunately when hitting your apache server the worm will be served a 404 page. this can take up a lot of bandwidth if a lot of worm threads are searching your sites. to stop these worms cold you can redirect their hits to an invalid host with the following code in your .htaccess file:

RedirectMatch (.*)cmd.exe$ http://www.lalafake.cominvalid$1
RedirectMatch (.*)root.exe$ http://www.lalafake.cominvalid$1
RedirectMatch (.*).dll$ http://www.lalafake.cominvalid$1

6. don’t have an access to a php settings? want to turn off register_global? put this in your .htaccess file:

<IfModule mod_php4.c>
php_flag register_globals off

7. want to password protect some file? here’s how:
a) put this in your .htaccess file:

<Files secret.html>
require valid-user
AuthName “Secret File”
AuthType Basic
AuthUserFile /path/to/your/.htpasswd

b) make sure you already have the .htpasswd file! refer to the article above.

there’s actually many more tips and tricks you can do with .htaccess, but this is the only thing i can give you. to sum it, i am lazy, find it yourself. he he he…okay, enjoy, have fun and happy experimenting…

More info [here]

Leave a Reply

Your email address will not be published. Required fields are marked *