• 22 Dec 2008 /  Web Design

    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: , ,

  • 21 Dec 2008 /  Web Design

    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: ,