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