This was sad, utterly sad. The first comment to this blog was a SPAM comment. I hate spam, so I’m going to add a few lines to my .htaccess file to prevent that IP from coming back and spamming me again.
What can you do with .htaccess banning?
1. Ban an IP
2. Ban an IP range (100.100.100.xxx), where xxx can be anything and will still be blocked
3. Ban a domain name. Ex: proxy1.c0oproxeh.com, proxy2.c0oproxeh.com will both be unable to view the site
Let’s get started. Here’s how you can block a single IP
order allow,deny
deny from 100.100.100.1
allow from all
Just switch out “100.100.100.1″ with the IP you want to block. That was pretty easy, wasn’t it? Now on to multiple IPs.
order allow,deny
deny from 100.100.100.1
deny from 100.100.100.2
deny from 100.100.100.3
deny from 100.100.100.4
deny from 100.100.100.5
allow from all
Now there are some tricky spammers out there who own multiple IPs with only slight variations. The most common way to attempt to prevent these spammers is to block every IP that has the first 3 sections the same (100.100.100). This is called IP range banning
order allow,deny
deny from 100.100.100
allow from all
Note that the above code will block 100.100.100.1, 100.100.100.2 ETC.
Last thing: Blocking a domain name (Like .com, .net etc)
order allow,deny
deny from c0oproxeh.com
allow from all
Final note: You can mix and match all of these! Here’s an example
order allow,deny
deny from c0oproxeh.com
deny from 100.100.100
deny from 200.200.200.2
allow from all
There ya go! Not hard at all. Just remember: Many hosts, mostly free hosts, will block custom .htaccess files.
Tags: ban, block ip, htaccess
You’re probably familiar with any major company having a nice, custom page when you land on a page that no longer exists. In this post, I will describe how you can add your own custom error pages with htaccess (assuming you are the webmaster).
First off, here are some common error codes and what they mean:
400: Bad Request
401: Authorization required
403: Forbidden
404: Page not found
500: Server error
Now, those might not mean much to you, but the most common error page and one that you should set is 404. If you so much as rename a file, visitors may be coming from google and the file doesn’t exist. Instead of seeing a bland white page (or your host’s 404 page), you should change it.
Here’s a sample .htaccess file
ErrorDocument 404 /404.html
ErrorDocument 500 /500.html
ErrorDocument 400 /400.html
ErrorDocument 401 /401.html
ErrorDocument 403 /403.html
You don’t have to name the file to match the error number, you can name the 404 error page “GoodbyeWorld.html” if you wanted.
Now: Some tips for creating this file. On Windows, you cannot easily create this file. It doesn’t like having only extensions for filenames. To solve this problem, simply create your file and name it htaccess or htaccess.txt. Then, upload it to your web server and from there you can change its name (from ftp or a control panel).
The most common problem people may face is due to their hosts: Many hosts, more specifically, many free hosts do not allow you to have a custom .htaccess file.
Tags: htaccess, web design
21 Dec 2008 /
Programming
There are just some things that google can never tell you, and no matter how hard you try to search for it you may never find what you are looking for. That happened to me when I tried to find out how to convert a String to an Integer array in Java. So, here’s the simple function that will do this:
1
2
3
4
5
6
7
8
9
| public static int[] strToInt (String inp) {
int[] toRet = new int[inp.length()];
int i = 0;
while(i < inp.length()) {
toRet[i]=(int)inp.charAt(i);
i++;
}
return toRet;
} |
This function goes through every character of the string and gets the integer value of the character and adds it to the integer array. When it’s done adding everything, it returns the integer array with the same length as the string.
(PS: Sorry for unindented code; I’ll have to find a better code plugin..)
Tags: java, Programming
21 Dec 2008 /
Uncategorized
So as a small number of you will notice, I wiped out the old site. The main reason being that I have just begun moving most random software related content to a fresh, new site about my software: matt-soft.com. The site is just being fleshed out, so most of the content from this site won’t be on there for a few days. This means that a lot of google visitors (who mostly want GameMaker examples) will just have to wait a bit. Considering that a good majority will get 404s, I’m going to bustle about and get up a 404 page by tomorrow which links to matt-soft.com.
So. What exactly will be in this blog? I have no idea yet. Maybe it’ll have some code snippets/examples, bits about my life, and random things I find interesting. We’ll find out.