Using .htaccess for type/charset in xhtml 1.1

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
brolly
Forum Newbie
Posts: 18
Joined: Thu May 25, 2006 7:24 am
Location: Nevada, U.S.A.

Using .htaccess for type/charset in xhtml 1.1

Post by brolly »

All my xhtml 1.1 pages with .html extensions have the following doctype. I also have that line in .htaccess. So I can't figure out why all my .html pages are shown as "text/html" when you "right-click in FireFox/View Page Info". Also, according to W3C.org placing a meta tag stating the type and charset in each .html file is incorrect/pointless.

Can anyone figure out why firefox shows "text/html" rather than "application/xhtml+xml"?

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >

Code: Select all

AddType application/xhtml+xml;charset=utf-8 .html
Last edited by brolly on Thu Jun 15, 2006 1:37 am, edited 2 times in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

are you sure the header returned says the content type is application/xhtml+xml?
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post by Roja »

At the top of the php file:

Code: Select all

header("Content-type: application/xhtml+xml; charset=utf-8");
User avatar
brolly
Forum Newbie
Posts: 18
Joined: Thu May 25, 2006 7:24 am
Location: Nevada, U.S.A.

Post by brolly »

Yes, I am sure, FireFox says that it is text/html.

The php method does not work because it says that there is already a header.

I got the answer: If I change the file extension to .xhtml, then FireFox states that it is application/xhtml+xml.

So... does anyone know if using an .xhtml extension is ok with google to crawl ?

Is there a way so that I won't have to use .xhtml (can a line be included in .htaccess to do this) ?
Last edited by brolly on Thu Jun 15, 2006 1:40 am, edited 1 time in total.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

If it says there is a header already then you are already began output to the browser. Try usig the header call before sending ANYTHING to the browser.

You shouldn't have to change the file extension to get the desired doctype. Using PHP headers should be enough.
User avatar
brolly
Forum Newbie
Posts: 18
Joined: Thu May 25, 2006 7:24 am
Location: Nevada, U.S.A.

Post by brolly »

I've been reading extensively and must point out that the whole idea of application/xhtml+xml is pointless because ie6 nor ie7 support it. So why bother then?
Last edited by brolly on Thu Jun 15, 2006 1:40 am, edited 1 time in total.
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post by Roja »

brolly wrote:I've been reading extensively and must point out that the whole idea of application/xhtml+xml is pointless because ie6 nor ie7 support it. So why bother then?
This isn't an easy answer, and you probably won't like it.

Because its right.

XHTML is meant to enable two things: Easier parsing (for machines/code/programs), and easier maintenance. If you want the easier maintenance, you are better off just making HTML strict.

If, however, you want to be all Web2.0-ish, and enable easy processing of your site for other programs, sites, etc, then XHTML is the clear choice.

Now, if you go the XHTML path, you should follow *all* the rules for XHTML, so that programs that are written to strictly follow standards will not get errors in dealing with your code. Thats what happens when you (incorrectly) serve XHTML as HTML or text, or similar.

But, you quickly shout, IE doesn't support it - oh woe!

Ah, but there is a way to do so. Simply provide an XSLT sheet for it, and even IE can enjoy the wonders of application/xml.

It shouldn't require that. It's a workaround. It's a hack. Its because Microsoft hasn't done any improvements on the most widely used browser in the world for several years - but it will allow you to be both standards compliant, AND jump on the XHTML bandwagon.

weee!

http://www.w3.org/MarkUp/2004/xhtml-faq#ie
User avatar
brolly
Forum Newbie
Posts: 18
Joined: Thu May 25, 2006 7:24 am
Location: Nevada, U.S.A.

Post by brolly »

That's great news, thank you very much! I'll implement it right away. Does this hack make ie work with xhtml 1.1 with application/xhtml+xml or only with xhtm 1.0 transitional with application/xml ?



But there is one problem: some of my pages use javascript such as document.write so it won't work in xhtml with application/... right ?

Will javascript work if I place the scripts in an external .js file or will it not work anyway ?

Code: Select all

<script type="text/javascript" src="whatever.js"></script>
Does javascript work in xhtml with text/html ?
Last edited by brolly on Thu Jun 15, 2006 1:41 am, edited 1 time in total.
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post by Roja »

brolly wrote:That's great news, thank you very much! I'll implement it right away. Does this hack make ie work with xhtml 1.1 with application/xhtml+xml or only with xhtm 1.0 transitional with application/xml ?
I'm honestly not sure. I generally stick to html strict, but if you test, and can report back on this thread, we'll all be much wiser thanks to you. (No sarcasm! I'm honestly curious!)
brolly wrote:But there is one problem: some of my pages use javascript such as document.write so it won't work in xhtml with application/... right ?
http://www.w3.org/MarkUp/2004/xhtml-faq#docwrite

In a nutshell, you can accomplish the same thing, you just need to use different methods (use the DOM!).
brolly wrote:Will javascript work if I place the scripts in an external .js file or will it not work anyway ?

Code: Select all

<script type="text/javascript" src="whatever.js"></script>
Does javascript work in xhtml with text/html ?
Absolutely, and that is the right way to do it. Javascript is still compatible with XHTML, you just have to use the DOM for most accessing of it.

Here's why. In HTML, the browser couldn't render (consistently) until it had everything, including the javascript (because people would document.write to it!). Many browsers tried (notably IE's shuffle-change model), but it resulted in completely inconsistent behavior.

In XHTML, they put the display up immediately, as soon as they have a workable parse tree - because the spec says it will NOT change (no document.write) until after the render (DOM can do so).

DOM actions take the parse tree for xml, and make specific changes to it after the fact, while document.write INJECTS new content during the parse of the page. Big (painful) difference.
User avatar
brolly
Forum Newbie
Posts: 18
Joined: Thu May 25, 2006 7:24 am
Location: Nevada, U.S.A.

Post by brolly »

Follow-up:

The php negotiation method with the hack for setting the charset and the type works perfectly and it works with xhtml 1.0 strict as well.

To solve the javascript problem I simply cut and pasted the scripts into a .js file and attached it to the .html file just like we said.

Thank you all for your help and expertise !
Post Reply