homepage Welcome to WebmasterWorld Guest from 54.227.171.163
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
setenv custom error page
Seedy



 
Msg#: 4434129 posted 9:39 pm on Mar 27, 2012 (gmt 0)

I've searched all over for this but unsuccessfully.

Can a custom error page be specified at the end of a set or 'SetEnv[IfNoCase]' deny rules or are they automatically served the custom 403 ?

I don't wish to use my current 403 page but serve a SetEnv rule-specific page.

eg:
SetEnvIfNoCase User-Agent "aaaaa" bad_bot
SetEnvIfNoCase User-Agent "bbbbb" bad_bot
<Limit GET POST PUT HEAD>
Order Deny,Allow
Deny from env=bad_bot
</Limit>
serve: custom-block.php



Thank you in advance

 

Key_Master

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 4434129 posted 10:16 pm on Mar 27, 2012 (gmt 0)

You can do this easily with mod_rewrite but using SetEnvIf gets a little more complicated (or not depending on your view).

When you set an environmental variable in .htaccess, your custom-block.php script has access to that same variable and its value. So in your script, you would need some code that would work check for that variable:

if variable bad_bot=1 { do something; }
lucy24

WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



 
Msg#: 4434129 posted 11:17 pm on Mar 27, 2012 (gmt 0)

You can definitely do it with a redirect, although that might be considered cheating. That is: redirect your Bad Files to a special directory, and set a different 403 document for that one directory. That's assuming they follow the redirect, which they might choose not to do. But if they're unwanted robots, you probably don't care if they just leave quietly.
____

Here's another thing that will not work (I tried) ;)

If you set more than one ErrorDocument, like
ErrorDocument 403 blahblah
ErrorDocument 403 blahblah
the most recent one will quietly replace any earlier ones. But if you block your Bad Requests from the most recent ErrorDocument, they will not bounce back to the earlier ErrorDocument. Instead you'll get an error message from the server.

Seedy



 
Msg#: 4434129 posted 7:34 am on Mar 28, 2012 (gmt 0)

Plenty of food for thought.
Many thanks for your replies guys ('n' gal).

Seedy



 
Msg#: 4434129 posted 8:24 pm on Mar 29, 2012 (gmt 0)

Guys - Lucy specifically - if I understood you correctly, what's the actual method of specifying a different error page to your regular 403 in htaccess for your SetEnv rules please? I'm wanting to give the redirect method a try first but am unsure how to action it in htaccess.
Thanks in advance

lucy24

WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



 
Msg#: 4434129 posted 10:43 pm on Mar 29, 2012 (gmt 0)

With the redirect method you don't use SetEnv at all. (I looked pretty hard, as I assume you did, but couldn't find an env= envelope. Just Files and Directory, and I forget the third.) You put an htaccess in the Directory For Icky Robots, with its own

ErrorDocument blahblah

statement. For example: my top-level htaccess has a series of

ErrorDocument 404 /boilerplate/missing.html

for the assorted common errors. Then, in the /dp/ directory I've got a one-line htaccess that says

ErrorDocument 404 /dp/missing.html

If someone's in this directory at all, they are probably following some ancient Forums link that I've forgotten all about, so they get customized information.

A directory-specific ErrorDocument statement overrides your generic rules in exactly the same way that you can switch auto-indexing off or on for individual directories. It will be inherited by subdirectories-- if there are any-- but will have no effect on other directories.

Seedy



 
Msg#: 4434129 posted 11:18 am on Mar 30, 2012 (gmt 0)

Understood. I'll give this a go and see if it's better than other methods.
Thank you Lucy.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved