Forum Moderators: phranque

Message Too Old, No Replies

Bad file requests

if so set an env variable for use elsewhere

         

matc

12:37 pm on Dec 23, 2004 (gmt 0)

10+ Year Member



Hello,

I was looking at a way of resolving bad file requests, which could be a cookie stated or query string request. The idea was to encompass the handle for these bad requests in one rule. Basically, if no file is found a environment variable is set to true and a piece of XSSI would use that to produce a default page.

Currently I've got this rule but it seems to presently set drop.query to true even with valid requests.

RewriteCond /home/system/www/data/vars/%{REQUEST_FILENAME}.shtml !-f
RewriteRule ^(.*)$ - [E=drop.query:true] #set env var

My head hurts a little bit so if anyone can help with this it would be much appreciated.

cheers, mat

jdMorgan

5:39 pm on Dec 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Since your variable is always being set, the most likely cause is that your server path for the filename is incorrect, so *no* files can be found.

This isn't likely to solve your problem, but you might consider using %{DOCUMENT_ROOT} instead of a hard-coded path... Something like:


RewriteCond %{DOCUMENT_ROOT}/vars/%{REQUEST_FILENAME}.shtml !-f

Also, this thread leaves me wondering why you are not using ErrorDocument 404, and pointing that to your script to generate an error page.

Jim

matc

10:42 am on Dec 31, 2004 (gmt 0)

10+ Year Member



Hi JdMorgan,

A very happy New Year to you and everyone else.

The reason for this question is that I'm in the last throws of replacing a service used to deliver geographically specific information. Each locations information is retrieved via a 4 digit id (0-9 range). The service excepts mainly query string based submissions which can be typed directly at the browsers address bar. The 4 digit id is taken by the service on good will as it should in the main part correspond to an existing data file. To allow for any mistypes :) a factory default id has been hard coded. The factory default is used by the service as a splash page and also to revert back to if a query can’t be resolved i.e. bad file request. The factory default will only kick in if the drop.query variable is set to true, however, presently this variable is always true.

I’m not totally sure why all the gremlins are out at the moment as the path used by the service is correct. Its surprising to see that even with valid submissions for files / ids that exist the drop.query var is still holding strong and only will return the factory default. Something that is even more baffling is that both the factory default, being returned with all its data present and correct, and the other existing test ids use the same path and can be found within the same directory.

Not really sure now where to go with this.

matc

matc

10:33 am on Jan 4, 2005 (gmt 0)

10+ Year Member



Hello,

cool, I looked at it again and have now just stated the file exists code to be specific to the actual form of request made. It now works fine.

#cookie param 1
RewriteCond %{HTTP_COOKIE} COOKIEONE=c1([0-9]+)
RewriteCond /home/system/www/data/vars/%1.shtml!-f
RewriteRule ^(.*)$ - [E=drop.query:true]

#cookie param 2
RewriteCond %{HTTP_COOKIE} COOKIETWO=c2([0-9]+)
RewriteCond /home/system/www/data/vars/%1.shtml !-f
RewriteRule ^(.*)$ - [E=drop.query:true]

#QS param 1
RewriteCond %{QUERY_STRING} Q1=([0-9]+)
RewriteCond /home/system/www/data/vars/%1.shtml !-f
RewriteRule ^(.*)$ - [E=drop.query:true]

#QS param 2
RewriteCond %{QUERY_STRING} Q3=([0-9]+)
RewriteCond /home/system/www/data/vars/%1.shtml!-f
RewriteRule ^(.*)$ - [E=drop.query:true]

If there's any way of retrieving these globally I would be very interested.

cheers, matc