Apache Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsSystem AdministrationApache Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old May 7th, 2008, 11:03 PM
dekallo dekallo is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 4 dekallo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 51 m 46 sec
Reputation Power: 0
IE choking on directory indexes served as xhtml

It always bothered me that when browsing directories without an index page you're stuck with the vanilla Apache directory index, so I set about figuring out how to make my file directories look good for file browsing.

Here's what I came up with:

Code:
httpd.conf
HeaderName "/autoindex/header.shtml"
ReadmeName "/autoindex/readme.shtml"

<Directory />
  Options Indexes Includes MultiViews FollowSymLinks
  AllowOverride None
  Order allow,deny
  Allow from all
  IndexOptions FancyIndexing XHTML SuppressHTMLPreamble NameWidth=* IconsAreLinks FoldersFirst SuppressDescription SuppressLastModified VersionSort IgnoreCase SuppressRules HTMLTable Type=application/xhtml+xml
  #IndexOptions Type=text/html
  IndexIgnore *.bak *~ 
  RewriteEngine On
  RewriteRule . - [E=DECODED_URI:%{REQUEST_URI}]
  RewriteCond %{HTTP_ACCEPT} !application/xhtml\+xml
  RewriteCond %{HTTP_ACCEPT} (text/html|\*/\*)
  RewriteCond %{REQUEST_FILENAME} .*\.xhtml
  RewriteRule . - [T=text/html]
</Directory>

<Directory "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/icons/">
  RewriteEngine Off
</Directory>

<Directory "C:/Users/Nick/Documents/My Website/autoindex/">
  RewriteEngine Off
</Directory>

-snip-
AddType application/xhtml+xml .xhtml

Code:
header.shtml
<?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" >

<head>
	<title>Index of <!--#echo var="DECODED_URI" --></title>
	<style type="text/css" media="all">@import "/autoindex/style.css";</style>
</head>

<body>

<h2>Index of <!--#echo var="DECODED_URI" --></h2>

Code:
readme.shtml
<!--#echo encoding="none" var="SERVER_SIGNATURE" -->
</body>

</html>


Here is a live demo: http://ntowle.dyndns.org/demo/

It works flawlessly in Firefox, and even validates as XHTML 1.1 through w3c. I'm actually very happy with the way it came out, way better than the standard Apache file directory. However, IE chokes completely when you try to browse a directory. I was able to verify that despite my rule up there, IE is still being served application/xhtml+xml and it errors out. I tried in vain several times to get the server to send text/html to IE, but for some reason it just kept sending the same old code. The line commented out in the conf, 'IndexOptions Type=text/html', fixes IE's problems but then serves the same dumbed-down mime-type to Firefox and other compliant browsers.

Is there a way I can serve my directory indexes as text/html to IE while keeping my application/xhtml+xml mime-type for Firefox and other browsers?

Reply With Quote
  #2  
Old May 8th, 2008, 08:35 AM
jharnois's Avatar
jharnois jharnois is offline
mod_dev_shed
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Sep 2002
Location: Atlanta, GA
Posts: 14,124 jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 1 Day 10 h 58 m 38 sec
Reputation Power: 717
Welcome to Dev Shed.

You really shouldn't "Allow from all" in the default <Directory />. See the Security Tips from the Apache documentation for more information.

If you want to take the mod_rewrite approach, you should 1) trace the headers that IE and Firefox are sending to make sure you're testing the right variable for the right string, and 2) use a RewriteLog to see what it's doing.
__________________
# Jeremy

Explain your problem instead of asking how to do what you decided was the solution.

Reply With Quote
  #3  
Old May 8th, 2008, 03:55 PM
dekallo dekallo is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 4 dekallo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 51 m 46 sec
Reputation Power: 0
Quote:
Originally Posted by jharnois
You really shouldn't "Allow from all" in the default <Directory />. See the Security Tips from the Apache documentation for more information.

It's was like that for testing purposes, I'll fix it.

Quote:
Originally Posted by jharnois
If you want to take the mod_rewrite approach, you should 1) trace the headers that IE and Firefox are sending to make sure you're testing the right variable for the right string, and 2) use a RewriteLog to see what it's doing.

My rewrite conditions are working fine, and according to the rewrite log, when /demo is loaded in IE it is writing the /demo/index.xhtml file to be sent as 'text/html' (after also looking for a index.php index.html index.htm etc as instructed by my DirectoryIndex command). This seems to me to be the problem, as there is no /demo/index.xhtml file because /demo is just a directory.

Is this fixable with mod_rewrite? Because it seems to me that since there's no actual static file being served to the browser that mod_rewrite might not be able to change the mime-type.

It should be noted that when IE requests an actual static .xhtml file the rewrite works as it should and IE is sent the page as 'text/html' while compliant browsers keep the original mime-type.

Thanks a lot for helping me out, and I'm open to any suggestions you may have, using mod_rewrite or otherwise.

Reply With Quote
  #4  
Old May 9th, 2008, 07:44 AM
jharnois's Avatar
jharnois jharnois is offline
mod_dev_shed
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Sep 2002
Location: Atlanta, GA
Posts: 14,124 jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 1 Day 10 h 58 m 38 sec
Reputation Power: 717
Quote:
Because it seems to me that since there's no actual static file being served to the browser that mod_rewrite might not be able to change the mime-type.
This is entirely possible, but I wouldn't know for sure. You might have to ask something like this on one of the Apache news groups where you might find more developers who have a higher understanding of the internal workings of Apache.


I wonder if you could somehow use an environment variable along with something like the Header to get what you need.

Reply With Quote
  #5  
Old May 9th, 2008, 11:53 AM
dekallo dekallo is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 4 dekallo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 51 m 46 sec
Reputation Power: 0
Quote:
Originally Posted by jharnois
This is entirely possible, but I wouldn't know for sure. You might have to ask something like this on one of the Apache news groups where you might find more developers who have a higher understanding of the internal workings of Apache.


I wonder if you could somehow use an environment variable along with something like the Header to get what you need.

Is there a way to test for the current request's mime-type using an environment variable or through some other method? Because then the rule wouldn't have to match to a document with an .xhtml extension and would rely on the mime-type of the document requested instead. I don't know if this is a possibility but it was something I thought of when trying to figure out how to make this work.

Reply With Quote
  #6  
Old May 9th, 2008, 02:43 PM
jharnois's Avatar
jharnois jharnois is offline
mod_dev_shed
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Sep 2002
Location: Atlanta, GA
Posts: 14,124 jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 1 Day 10 h 58 m 38 sec
Reputation Power: 717
You can set an environment variable based on a test against another variable like you've done in your rewrites. So you could use mod_rewrite to test the HTTP_ACCEPT header and set an environment variable of use_xhtml or whatever to true and use that later.

You could probably also do this with SetEnvIf[NoCase].

Reply With Quote
  #7  
Old May 9th, 2008, 05:54 PM
dekallo dekallo is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 4 dekallo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 51 m 46 sec
Reputation Power: 0
As far as I know it isn't possible to set the Content-Type with Headers. I tried something like
Code:
httpd.conf
SetEnvIfNoCase REQUEST_URI "\.xhtml$" REJECT_XHTML
SetEnvIfNoCase REQUEST_URI "/*$" REJECT_XHTML
Header set Content-Type "text/html" env=REJECT_XHTML

but this didn't work. I have about 30 lines of commented out code now from random experiments I've tried with both mod_rewrite and with SetEnvIf but none of them got me anywhere.

Reply With Quote
Reply

Viewing: Dev Shed ForumsSystem AdministrationApache Development > IE choking on directory indexes served as xhtml


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway