Forum Moderators: phranque

Message Too Old, No Replies

Accessing content by case insensitive reference

Mixed case reference to local file gives Error 404

         

longmint2

11:14 pm on May 23, 2009 (gmt 0)

10+ Year Member



Hi

I'm a newbie to publishing on a public server and have a silly question (I'll explain the reason why later but to the problem...)

I have a limited webspace hosted with Apache V1.3.37; it seems to allow the ReadWrite module - I can use .htaccess to redirect my domain to the canonical domain and point to ErrorDocuments (but no PHP support etc.).

Can I use readwrite to allow an html page to access a bmp file on the local site when the case is inconsistant?

The web page is located in /inr/PRNTREP.HTM and refers to an img in /inr/img/pads/PtTrend2.bmp but the file is named PTTRENDS.BMP.
I'm using .htaccess (located in /inr) with the following content to try to redirect the pathname:

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} -d
ReWriteRule ^(.*)pttrend(\d*)\.bmp $1PTTREND$2.BMP [NC,L]

but I get a 404 error.

Am I trying to do something which is not achievable? - 1).htaccess in correct directory? 2)Syntax OK? 3)Trying to achieve the impossible?

Reason:
I want to publish on to the website from a device which produces medical information (INR blood tests) locally using html and javascript (but is volatile). I can publish two,automatically produced, files (PRNTREP.HTM & PTTREND2.BMP) to my site to give the information to the medics who can inform me on the medication I have to take. I realise I could rename the PTTREND2.BMP to PtTrend2.bmp but that would be too easy...?

Be kind -

jdMorgan

3:44 am on May 24, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your code requires that the requested file does not exist as a file, but does exist as a directory, because the NOT operator "!" is missing in the second RewriteCond.

I strongly suggest that you use an external redirect to do this, and further that you make sure the images are marked as non-cacheable. This latter may not be possible on your limited-capability server, in which case you should both use an external redirect *and* change the image URL on a daily/hourly basis. If you do not take these steps, it is likely that "the medics" will see a stale cached image, and that could be quite dangerous.

Do not try to use PCRE (PERL-Compatible Regular Expressions) with Apache 1.3x -- It supports only POSIX regular expressions.

In www.example.com/inr/.htaccess


Options +FollowSymlinks
RewriteEngine on
#
# If requested image URL-path is not properly cased
RewriteCond $1 !^img/pads/PTTREND[0-9]*\.BMP$
# Redirect to uppercase image URL
RewriteRule ^(img/pads/pttrend([0-9]*)\.bmp)$ http://www.example.com/inr/img/pads/PTTREND$2.BMP [NC,R=301,L]
#
<FilesMatch "PTTREND[0-9]*\.BMP$">
ExpiresActive On
ExpiresDefault A0
ErrorHeader set Cache-Control: "no-store"
</FilesMatch>

This is an example only. If you choose to use this example, neither I nor WebmasterWorld will accept any responsibility for the results.

It would certainly be simpler (and safer) to link to the bmp file using whatever case it is actually produced with, and so avoid the complications of rewriting/redirecting or renaming files.

Again, be very careful with client-side caching issues. If the image is cached, then their browser will not request a fresh version from your server, and they will see a stale image. The cache-control code I included in the example code above may cause errors if those directives are not supported on your server. If so, then you should make sure that the image URL changes every time you update the image on your server.

Given the server and other limitations, this project impresses me as rather unsafe, and I advise against it.

Jim

[edited by: jdMorgan at 4:08 am (utc) on May 24, 2009]

longmint2

3:45 pm on May 24, 2009 (gmt 0)

10+ Year Member



Thanks for your excellent prompt reply Jim - it's filled in a lot of 'grey areas'.

I've tried your suggestion and the outcome is as follows:

1) The <quote>
<FilesMatch "PTTREND[0-9]*\.BMP$">
ExpiresActive On
ExpiresDefault A0
ErrorHeader set Cache-Control: "no-store"
</FilesMatch>
</quote>
doesn't work on my webspace provider (Error 500 response).

2) The bmp file still does not display but now I get a 301 response:
"GET /inr/img/pads/PtTrend2.bmp HTTP/1.1" 301 337 "-" "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10 (.NET CLR 3.5.30729)"
(It may be a caching problem)

I'll take on your reservations on the project. This is a novel experience and I believe that I'm a small minority using this device in the first place - let alone using it to publish the results...
The medics will still follow their procedures - I'm just trying to provide useful information to them (even though it may be outdated because of the technology).What I'm trying to say that the information provided is not critical.

I intend to take your advice and refer to the content as is...

The way I'm thinking is to produce a program to update the website. Because of the limitations of the webspace (no PHP or server side support) this would be a stand alone program; but I would like to use a password protected page to do this -- another thread!.

Just to cross the t's, dot the i's and for reference I have a couple (or 3) questions on your response.

a) Could I inform the clients to refer to the page by using a technique such as putting an empty query string on the url?
b) What is the function of 'ErrorHeader set Cache-Control: "no-store"' achieving (had a look at the directives but can't make head or tail?)
c) In your <quote>If so, then you should make sure that the image URL changes every time you update the image on your server. </quote>
Does this mean I should change the reference, filename or an Apache directive?

jdMorgan

4:48 pm on May 25, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> a) Could I inform the clients to refer to the page by using a technique such as putting an empty query string on the url?

You could, assuming you mean "inform the visitor," and not the user-agent (e.g. browser), but can you count on them to do so? I think not.

--

> b) What is the function of 'ErrorHeader set Cache-Control: "no-store"' achieving (had a look at the directives but can't make head or tail?)

To make the resource un-cacheable by network or browser caches.

The directive only says, "output this header." For a definition of the what that header means, you'll have to look at the HTTP specifications (RFCs), or try a search for "HTTP Cache-Control no-store".

--

> c) In your reply, "If so, then you should make sure that the image URL changes every time you update the image on your server."
Does this mean I should change the reference, filename or an Apache directive?

As stated, I meant change the URL. Cache entries are 'stored' by URL, so changing the URL bypasses the problem of having a previously-cached version in the browser or network caches.

It's a bit of an advanced topic, but you could to *externally redirect* all requests for the resource to a URL that has a datestamp - e.g. http://www.example.com/inr/img/pads/PTTREND$2-20090525134559.BMP, and then *internally rewrite* such requests back to the 'real file.' The link on your page can be generated using SSI (Server-Side-Includes) so that it updates based on the server's internal clock or the file's Last-Modified timestamp. In the example here, the file was updated on May 25th, 2009, at 1:45:59 PM.

This is a hack, though, and marking the resource as uncacheable is the proper solution.

Jim

longmint2

9:56 pm on May 25, 2009 (gmt 0)

10+ Year Member



Thanks Jim - I feel I'm getting over my head here - but from what you state makes me realise that you've got to be very careful in providing up-to-date info through a website. Thanks very much for your input- I've learnt alot.

Rob