meta redirect - on removing .htm extension, Firefox displays HTML - Why?

D

David Smithz

Hi there,

I wanted to implement a meta redirect so that when users visiting a website
just type the following for example

www.example.com/downloads

instead of

www.example.com/downloads.htm

I wanted the visitor to be redirected to the .htm page.

I therefore created a very simple page which just has a meta tag redirect
which does the appropriate redirect.

This worked fine, however, when I remove the .htm file name from the file,
and then view it on Firefox browser, it actually just displays the HTML
code.
How can I make it work so it does not should the HTML code?

An example of the code I use is below:

**********************************************
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="refresh" content="0;
URL=http://www.example.com/downloads.htm">
<title>example - downloads redirect</title>
</head>

<body>
<p>...redirect to download page...</p>
<p>or click below if your browser does not support redirects</p>
<p><a href="./downloads.htm">downloads.htm</a></p>
<p>&nbsp;</p>
</body>
</html>
*********************************************
 
P

PeterMcC

David Smithz wrote in
Hi there,

I wanted to implement a meta redirect so that when users visiting a
website just type the following for example

www.example.com/downloads

instead of

www.example.com/downloads.htm

I wanted the visitor to be redirected to the .htm page.

I know its not the meta redirect answer you sought but...

....if you were to make a sub-directory called "downloads", put your
downloads.htm file in there and rename it to index.htm(l) then anyone typing
www.example.com/downloads would get the page currently accessed as
www.example.com/downloads.htm

It may be worth mentioning that there are usability and search engine
problems associated with the meta redirect.
 
D

David Smithz

PeterMcC said:
I know its not the meta redirect answer you sought but...

...if you were to make a sub-directory called "downloads", put your
downloads.htm file in there and rename it to index.htm(l) then anyone
typing
www.example.com/downloads would get the page currently accessed as
www.example.com/downloads.htm

Actually, I do have that system in place already for other pages, but in
this case I do now want to setup a specific folder.
It may be worth mentioning that there are usability and search engine
problems associated with the meta redirect.
I did not know that so thanks. Then again, in this circumstane, this is not
a page I want particular available to public, just for people I tell so
there is no link from the main website.

Thank you for your input.
 
A

Alan J. Flavell

I wanted to implement a meta redirect

True redirection is done by an HTTP 30x status response (status 301
permanent redirection would be appropriate, in your case). Abusing
the "meta...refresh" construction, especially with zero delay, is a
pesky nuisance to a lot of users, quite apart from being a violation
of WAI guidelines.[1]
so that when users visiting a website just type the following for
example

www.example.com/downloads

instead of

www.example.com/downloads.htm

I wanted the visitor to be redirected to the .htm page.

If that's what you want to achieve, then configure the server to issue
the HTTP redirection transaction accordingly.
This worked fine, however, when I remove the .htm file name from the
file, and then view it on Firefox browser, it actually just displays
the HTML code.

Almost certainly that's because your server is sending it out as
Content-type: text/plain

This is nothing specific to Firefox - the same behaviour would be
expected with any specification-conforming client agent. (Which
typically excludes MSIE: recent security fixes have gone some
way to correct their earlier misbehaviour in this specific area, but
without correcting the fundamental fact that they are deliberately
violating a mandatory requirement of RFC2616).
How can I make it work so it does not should the HTML code?

One would configure the server to send it with the appropriate
Content-type header.

This is a general technique which anyone offering material on the web
would need to master, by one means or another.[2] But it's the wrong
approach to dealing with this particular problem.
An example of the code I use is below:

But it's useless here, because the results depend on how your server
is configured, and we can't see that from a usenet posting.
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">

This comes too late. If the server says Content-type: text/plain then
text/plain is what it is. You can't change that by inserting stuff
that would only have meaning when the content type is text/html. The
whole point of text/plain is that the client agent *must* not
interpret anything which it finds in the content body, no matter how
many pointy-brackets it seems to contain.
<meta http-equiv="refresh" content="0;
URL=http://www.example.com/downloads.htm">

And that is what you should not do.

http://www.w3.org/QA/Tips/reback

regards

[1] WAI 1.0 certainly rated it as a violation. I see that for some
bizarre reason the draft 2.0 guidelines are rating it as acceptable,
with the true HTTP redirection rated as only "preferable" - heaven
knows why they say that: let's hope someone knocks some sense into
it before the draft is finished.

http://www.w3.org/TR/WCAG10-HTML-TECHS/#meta-element
http://www.w3.org/TR/2005/WD-WCAG20-HTML-TECHS-20050630/#meta_redirect

[2] http://ppewww.ph.gla.ac.uk/~flavell/www/content-type.html might
be of interest.
 
D

David Smithz

Thanks for your truly useful comments Alan.

I started looking into this and it certainly looks the way forward.
Considering I'm on a shared hosting accounts, is one able to do the
necessary changes to the Apache server ( I know it is probably different for
each host, but generally).

Also, despite reading a lot of the information sent, I'm still a long way
from understanding how to do it. Is there anywhere just a quick example of
where I actually make the changes and what I need access to.

A lot of the links assumed knowledge of things I am not yet familar with and
in the short term I wanted to get things up and running ASAP. I will then
look to make it work the proper way.

I know I have access to .htaccess file with my host. Would that be
somewhere, where I could make these changes?

Thanks and sorry for newbieishness of my question.

Dave.
 
A

Alan J. Flavell

I know I have access to .htaccess file with my host. Would that be
somewhere, where I could make these changes?

Absolutely.

OK, let's start by trying to answer the question which you actually
asked.

The key to your redirection (as I hope you already read in the cited
supporting materials) could be some flavour of Apache Redirect
statement (in your .htaccess file, that is).

Redirect 301 /downloads http://www.example.com/downloads.htm

(301 is the permanent status already mentioned).

There are much more elaborate possibilities as one moves along,
including RedirectMatch with regular expressions; Redirect or
Thanks and sorry for newbieishness of my question.

Not at all - we all have to start somewhere. The important point is
to want to learn ;-)


Peter McC has already suggested one alternative approach, namely to
turn downloads into a directory and put your page as its default
document - by convention index.htm or index.html ...

However, as exhibited, that was slightly sub-optimal, since navigating
to http://www.example.com/downloads is going to cause the web server
to redirect to http://www.example.com/downloads/ (with the trailing
"/") before it returns the default document.

*If* you decided to follow that approach, your references should
really be directly to http://www.example.com/downloads/ , so as to
avoid the unnecessary redirection transaction.


Another approach is to leave the web server to supply the missing
filename extension internally, without mentioning it on the URL.
In this case, no redirection transaction takes place: the document
is directly referenced by its URL http://www.example.com/downloads
despite the fact that your actual file, internal to the server, is
called downloads.htm (or .html, as the case may be). If you activate
MultiViews then you can have this and much else - but that would take
us off into lots of other detail.


Changing the subject again: you had a question to which I suspected
the answer was that your server was returning text/plain as the
content type. You didn't say anything in your followup to confirm or
deny that, but you might want to know how to influence that...

It's unlikely to be a good idea to set the server's default
content-type to be text/html, since in general there could be all
manner of unknown content types which it would be harmful to serve out
as text/html.

By convention, there's been two "schools of thought" about what to do
with unknown content-types. One is to serve them out as text/plain in
the hope that the reader will be able to make some sense of them
anyway. This can be particularly useful when there are miscellaneous
files lurking around with names like README or CHANGELOG or INSTALL.
But not so useful if the files of unknown type contain binary
executables and what not.

The other school of thought is to make the general default type to be
application/octet-stream (which in effect means "this is some bag of
bytes and I don't know what it's for, you might as well download it").

And then to take care to provide some special configuration for files
which, although they are without filename extensions, it's known that
they were meant to contain text, or some other definite content-type.

hope this is useful - it's really an open-ended topic, could go on and
on - but take what you need for now, and look to learn more when you
need it later.
 
D

David Smithz

Eureka!

I've got it working using the redirects and I really like it. Now on any
websites I do I can setup redirects like this as I think it's useful to be
able to type in the domain name and then just type a keyword (e.g.
www.example.com/download) to be taken to wherever that information is on the
website.

It seems to work fin so thanks for all your input Alan,

Incidentally I did not use the 301 in front of the original path like you
have in your example, but I assume this is OK.

As for what my host served as default content, I was unsure, but from
getting an understanding with the help of your post in the last few hours I
believe it is text/plain.

Thanks again.

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top