Welcome to the JaguarPC Community
JaguarPC
Sales: (888) 338-5261
Support: (888)-551-3050
Results 1 to 6 of 6

This is a discussion on Custom 403 page not working... in the Shared & Semi-Dedicated forum
My custom 403 error page isn't working for IPs banned by "deny from" in .htaccess. I get the [an error occurred while processing this directive] ...

  1. #1
    Ron
    Ron is offline
    Loyal Client
    Join Date
    Aug 2002
    Posts
    7,307

    Custom 403 page not working...

    My custom 403 error page isn't working for IPs banned by "deny from" in .htaccess. I get the [an error occurred while processing this directive] error message. The code works for other 403-forbidden errors, like trying to view a directory.

    I think I know why; the IP address is banned from accessing all files on the site, and I'm exec'ing a common CGI perl program from the 403 page.

    I thinking that I'm hosed. Anyone else have any luck with this?

  2. #2
    JPC Member
    Join Date
    Oct 2004
    Posts
    11
    I think you would have to do an IP redirect instead of a deny

  3. #3
    Ron
    Ron is offline
    Loyal Client
    Join Date
    Aug 2002
    Posts
    7,307
    I am unfamiliar with IP redirects. Something easy to explain or should I Google it?

  4. #4
    || $name ne 'R.Stiltskin'
    Join Date
    Jun 2003
    Location
    Tejas
    Posts
    2,438
    Working for me. I think I'm replicating what you want to do. So, in .htaccess:
    Code:
    ErrorDocument 403 /cgi-bin/403_response.cgi
    And for a cgi-script (permissions 0711):
    Code:
    #!/usr/bin/perl
    #--------------------------------------------------
    # 403_response.cgi   ver 0.00.01
    # Custom 403 response via CGI
    # 7/28/2006 08:02:25 PM
    # Copyright © 2006 HistoSoft Corporation
    # All Rights Reserved
    #--------------------------------------------------
    #
    use v5.6.1;
    #use lib qw( /path/to/local/lib/perl5 ); #optional path to private libs
    use warnings;
    use strict;
    use CGI;
    #use CGI::Carp qw(carpout fatalsToBrowser); #uncomment to view errors;
    
    my $query;
    $query = new CGI;
    print $query->header(
        -type    => 'text/html',
        -charset => 'ISO-8859-1',
        -expires => '+1m',
    );
    print $query->start_html(
        -lang     => 'en-US',
        -encoding => 'iso-8859-1',
        -meta     => {
            'robots'       => 'noindex,follow',
            'description'  => 'Domain » Site Maintenance 403 Response',
            'rating'       => 'general',
            'distribution' => 'global',
            'MSSmartTagsPreventParsing' => 'true',
            'copyright'    => 'Copyright(c)2006 HistoSoft Corporation. All Rights Reserved.',
        },
        -title => '403 Error » Forbidden Access',
        -head  => [
            $query->Link( { -rel => 'shortcut icon', -href => 'favicon.ico', -type => 'image/x-icon' } ),
            $query->meta( { -http_equiv => 'imagetoolbar', -content => 'no' } ),
            $query->meta( { -http_equiv => 'Cache-Control', -content => 'private,max-age=60,no-transform' } ),
            $query->meta( { -http_equiv => 'expires', -content => '+1m' } )
        ],
        #-style  => { -src => ['CSSstyle/custom.css'] },
    );
    print "\n";
    print <<XHTML;
    <h1 style="text-align: center; color: #193e5b";>Whoops!</h1>
    <p style="text-align: center">You don't have access here.</p>
    <p style="text-align: center">Sorry.<br />
    Please visit a little later or try another page at 
    <a href="http://www.domain.com">www.domain.com</a>.</p>
    XHTML
    print $query->end_html();
    
    exit 0;
    I'm receiving the appropriate 403 headers in my client, so Apache is returning the proper interpreted header. I do not need to use a non-parsed header script and define a 403 explicitely.

    See if this will work for you.

  5. #5
    || $name ne 'R.Stiltskin'
    Join Date
    Jun 2003
    Location
    Tejas
    Posts
    2,438
    By the way, I used a Deny from rule in my root .htaccess to block myself and it worked just fine.

  6. #6
    Ron
    Ron is offline
    Loyal Client
    Join Date
    Aug 2002
    Posts
    7,307
    Thanks Spathi. The errordoc entry in .htaccess is probably the basis of the solution to my problem. My head was stuck on the CPanel redirect to the error doc. I didn't think of the root of the problem.

    I think the problem is I've got my error document as 403.shtml, and then it execs the perl script. My script writes to a logfile. I wrote the solution back in 2001, perhaps a little earlier. I never look at the durn logs anymore except time like today when I banned an IP addy, and wanted to see their access attempts.

    So, perhaps a re-thinking of what (if anything) I want to accomplish now is in order. I played around several weeks ago with giving a 404 result while displaying the contents of my home page- that was pretty cool. (My thinking was "I can't figure out what you're looking for, so here, look at this instead.") That might lead me to parsing out the request URI, dropping the obvious and ubiquitous hacking attempts and trying to display something relevant, perhaps a search results page or some such.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •