XHTML Madness!

thorx10

New Member
Messages
5
Reaction score
0
Points
0
I am brand new to web design so please forgive my obvious ignorance.

I am a little confused about serving an XHTML webpage as application/xhtml+xml. When I do so, and I click View Page Info in Mozilla's (3.5.1) context menu it says that the Type is text/html. Below this, in the Meta section it says:

Content-Type: application/xhtml+xml; charset=utf-8

Why does it say the Type is text/html when the Content Type is application/xhtml+xml?

When I serve the page as php and use a bit of code to detect if the browser can accept the application/xhtml+xml MIME type, Mozilla does in fact display the Type as application/xhtml+xml.

How can I serve the file as application/xhtml+xml for Firefox (and other browsers) using html only?

Examples:

HTML: www.hollowpursuits.x10hosting.com/test (View Page Info)
PHP: www.hollowpursuits.x10hosting.com/corporama (View Page Info)

Any help or insight would be greatly appreciated!

Thanks in advance.
 
Last edited:

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
How did you try configure Apache to serve "test" as "application/xhtml+xml"? Whatever it was, it didn't work. If you view the "Headers" tab in the Page Info window (or use the Live HTTP Headers add-on), you'll see that Apache sends a "Content-type: text/html" header for the page.
 
Last edited:

thorx10

New Member
Messages
5
Reaction score
0
Points
0
Thanks for the reply, and for the Headers add-on.

I didn't perform any configuration of the Apache server. I simply uploaded the .html file to my x10Hosting subdomain via ftp (the same way I did with the php page). Do I need to configure something in cPanel so that the .html files are served as "application/xhtml+xml" when the Content-Type is "application/xhtml+xml" in the file?

If it helps, here is the header code used on the php page:

<?php
if (stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml")) {
header("Content-type: application/xhtml+xml");
echo '<?xml version="1.0" encoding="utf-8"?'.'>';
}
else {
header("Content-type: text/html; charset=utf-8");
}
?>

Basically all I want to do is to have the browser use the application/xhtml+xml MIME type when I use a .html file.



---Later---


After some reading on the issue, it seems that I need to add the following to the .htaccess file:

# XHTML
AddType application/xhtml+xml .xhtml

There is a .htaccess file in the public_html directory. Is this the one that should be modified, and if so, where should this code be added within the file?

Is it possible to edit this via cPanel or should I download the file via ftp, modify it, and upload it again?

(Sorry, total beginner) :confused:



---Even later---


Sorted! I just needed to create a .htaccess file in the appropriate directory with one line of code:

AddType application/xhtml+xml .html

(AddType [MIME-type] [extension])

Thanks misson, for pointing me towards the Apache server. Also, the Live HTTP Headers add-on for Mozilla is made out of win!

:biggrin:
 
Last edited:

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Since you had to set the header when using PHP, it's a safe bet that Apache won't do it on its own. After all, Apache is the intermediary between browsers and PHP scripts.

You can set MIME types within cPanel, but not conditionally. To do that, editing .htaccess is the way to go. AddType is what cPanel uses under the hood; it can only unconditionally set the content type. To conditionally set the Content-type header, you might be able to make use of: SetEnvIf, RewriteCond+RewriteRule, Header. Try something like:
Code:
RewriteCond %{HTTP_ACCEPT} application/xhtml\+xml
RewriteCond %{REQUEST_FILENAME} \.x?html$
RewriteRule . - [E=XHTML:1]

Header set Content-type "application/xhtml+xml" env=XHTML

While you're at it, begin to familiarize yourself with the rest of the Apache module documentation, which explains the various Apache configuration options, and which can be used in .htaccess.
 
Last edited:

thorx10

New Member
Messages
5
Reaction score
0
Points
0
Conditional! Now that's what I'm talking about. I will have a go at this code too.
 
Top