This is a discussion on Can I call a differerent 302 error handlers ?? within the Apache Web Server forums, part of the Web Server and Related Forums category; I have a web page which is accessible only from the UK. So if you go to http://www.southminster-...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I have a web page which is accessible only from the UK. So if you go to
http://www.southminster-branch-line....book/where.cgi it will *either* a) Print some simple text telling you it thinks you are in the UK or b) Print a web page saying "Permission denied (believed to be outside the UK)" The latter will occur if you are outside the UK since it generates a 302 error and I have an handler for that. The problem is that since this is under the /cgi-bin/guest-book/ directory, an attempt to list the directory contents, as you will do if there is no filename on the end - i,e, http://www.southminster-branch-line....in/guest-book/ will *also* generate a 302 error but for a different reason. So in that directory, two different problems both cause a 302 error. Is there a way to have two error handlers, such that 1) One is generated if open http://www.southminster-branch-line....book/where.cgi with an IP address outside the UK, OR 2) Another is generated if you try to list the contents of the directory http://www.southminster-branch-line....in/guest-book/ no matter where in the world you are? It seems an impossibility, since both generate a 302 error for quite different reasons. But is there a way around it? The Virtual Host is below. I'm running Apache 2.0.52 on a Sun SPARCstation 20 running Solaris 9. <VirtualHost *:80> ServerAdmin david.kirkby@onetel.net DocumentRoot /usr/local/apache2/htdocs/Southminster-branch-line Options ExecCGI Indexes FollowSymLinks Includes ServerName www.southminster-branch-line.org.uk # Note, the first 403 error handler ErrorDocument 403 /error-messages/forbidden-403.shtml CustomLog /usr/local/apache2/logs/access_log-Southminster-branch-line combin ed ScriptAlias /cgi-bin/ "/usr/local/apache2/htdocs/Southminster-branch-line/ cgi-bin/" <Directory /usr/local/apache2/htdocs/Southminster-branch-line/cgi-bin/guest- book > # Note a specific one for this directory. ErrorDocument 403 /error-messages/forbidden-not-UK-403.shtml <IfModule mod_geoip.c> GeoIPEnable On SetEnvIf GEOIP_COUNTRY_CODE GB AllowCountry # SetEnvIf GEOIP_COUNTRY_CODE RU BlockCountry # ... place more countries here Deny from all Allow from env=AllowCountry Allow from 192.168.0.0/255.255.0.0 </IfModule> </Directory> </VirtualHost> |
|
|||
|
Dave wrote:
> I have a web page which is accessible only from the UK. [...] > The latter will occur if you are outside the UK since it generates a 302 > error and I have an handler for that. Well, it is a 403 forbidden error. > It seems an impossibility, since both generate a 302 error for quite > different reasons. But is there a way around it? May be try the FilesMatch directive to override the ErrorDoc again: <Directory /usr/local/apache2/htdocs/Southminster-branch-line/cgi-bin/guest- book> # Note a specific one for this directory. ErrorDocument 403 /error-messages/forbidden-not-UK-403.shtml <FilesMatch "^/cgi-bin/guest-book/$"> ErrorDocument 403 /error-messages/forbidden-403.shtml </FilesMatch> <IfModule mod_geoip.c> GeoIPEnable On SetEnvIf GEOIP_COUNTRY_CODE GB AllowCountry # SetEnvIf GEOIP_COUNTRY_CODE RU BlockCountry # ... place more countries here Deny from all Allow from env=AllowCountry Allow from 192.168.0.0/255.255.0.0 </IfModule> </Directory> -- Robert |
|
|||
|
Dave wrote:
> I have a web page which is accessible only from the UK. So if you go to > http://www.southminster-branch-line....book/where.cgi > it will *either* > a) Print some simple text telling you it thinks you are in the UK or > b) Print a web page saying "Permission denied (believed to be outside > the UK)" > The latter will occur if you are outside the UK since it generates a 302 > error and I have an handler for that. A 302 is not an error, it is a redirect. > The problem is that since this is under the /cgi-bin/guest-book/ > directory, an attempt to list the directory contents, as you will do if > there is no filename on the end - i,e, > http://www.southminster-branch-line....in/guest-book/ > will *also* generate a 302 error but for a different reason. So in that > directory, two different problems both cause a 302 error. Drop an "index.html" into that directory which will display whatever message you write. A presumption is your Apache is configured to displayed index.html (or similar) in place of directory indexing. There is no need to redirect to prevent directory indexing. For your where.cgi application, there is also no need to redirect. Simply write code in your where.cgi to display your "outside UK" message when this condition is detected, hopefully correctly. Purl Gurl |
|
|||
|
Robert Ionescu wrote:
> Dave wrote: > >> I have a web page which is accessible only from the UK. > > [...] > >> The latter will occur if you are outside the UK since it generates a >> 302 error and I have an handler for that. > > > Well, it is a 403 forbidden error. Sorry, my mistake. I don't know what I was thinking. >> It seems an impossibility, since both generate a 302 error for quite >> different reasons. But is there a way around it? I obviously ment 403. > > May be try the FilesMatch directive to override the ErrorDoc again: > > <Directory > /usr/local/apache2/htdocs/Southminster-branch-line/cgi-bin/guest- > book> > > # Note a specific one for this directory. > ErrorDocument 403 /error-messages/forbidden-not-UK-403.shtml > > <FilesMatch "^/cgi-bin/guest-book/$"> > ErrorDocument 403 /error-messages/forbidden-403.shtml > </FilesMatch> > > > <IfModule mod_geoip.c> > GeoIPEnable On > SetEnvIf GEOIP_COUNTRY_CODE GB AllowCountry > # SetEnvIf GEOIP_COUNTRY_CODE RU BlockCountry > # ... place more countries here > Deny from all > Allow from env=AllowCountry > Allow from 192.168.0.0/255.255.0.0 > </IfModule> > </Directory> > > Thank you, but that unfortunately that does not work. It always displays the forbidden-not-UK-403.shtml if there is an error. I tried reversing the match, making it specific to the one file, so it reads: ErrorDocument 403 /error-messages/forbidden-403.shtml <FilesMatch "^/cgi-bin/guest-book/where\.cgi"> ErrorDocument 403 /error-messages/forbidden-not-UK-403.shtml </FilesMatch> but that always loads forbidden-403.shtml |
|
|||
|
Dave wrote:
> Robert Ionescu wrote: >> Dave wrote: >> >>> I have a web page which is accessible only from the UK. >> >> [...] >> >>> The latter will occur if you are outside the UK since it generates a >>> 302 error and I have an handler for that. >> >> >> Well, it is a 403 forbidden error. > > > Sorry, my mistake. I don't know what I was thinking. > >>> It seems an impossibility, since both generate a 302 error for quite >>> different reasons. But is there a way around it? > > I obviously ment 403. > >> >> May be try the FilesMatch directive to override the ErrorDoc again: >> >> <Directory >> /usr/local/apache2/htdocs/Southminster-branch-line/cgi-bin/guest- >> book> >> >> # Note a specific one for this directory. >> ErrorDocument 403 /error-messages/forbidden-not-UK-403.shtml >> >> <FilesMatch "^/cgi-bin/guest-book/$"> >> ErrorDocument 403 /error-messages/forbidden-403.shtml >> </FilesMatch> >> >> >> <IfModule mod_geoip.c> >> GeoIPEnable On >> SetEnvIf GEOIP_COUNTRY_CODE GB AllowCountry >> # SetEnvIf GEOIP_COUNTRY_CODE RU BlockCountry >> # ... place more countries here >> Deny from all >> Allow from env=AllowCountry >> Allow from 192.168.0.0/255.255.0.0 >> </IfModule> >> </Directory> >> >> > > I tried reversing the match, making it specific to the one file, so it > reads: > > > ErrorDocument 403 /error-messages/forbidden-403.shtml > > <FilesMatch "^/cgi-bin/guest-book/where\.cgi"> > ErrorDocument 403 /error-messages/forbidden-not-UK-403.shtml > </FilesMatch> > > but that always loads forbidden-403.shtml Oh sorry, this is filesmatch, not location, so it will match only against files, not folders, so I think ErrorDocument 403 /error-messages/forbidden-403.shtml <FilesMatch "where\.cgi$"> ErrorDocument 403 /error-messages/forbidden-not-UK-403.shtml </FilesMatch> should do it. -- Robert |
|
|||
|
Robert Ionescu wrote:
> Oh sorry, this is filesmatch, not location, so it will match only > against files, not folders, so I think > > ErrorDocument 403 /error-messages/forbidden-403.shtml > > <FilesMatch "where\.cgi$"> > ErrorDocument 403 /error-messages/forbidden-not-UK-403.shtml > </FilesMatch> > > should do it. > Thank you very much - that solved it. It now loads one of two error handlers for error 403. |