|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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? |
|
#2
|
||||
|
||||
|
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. |
|
#3
|
||||
|
||||
|
Quote:
It's was like that for testing purposes, I'll fix it. Quote:
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. |
|
#4
|
||||
|
||||
|
Quote:
I wonder if you could somehow use an environment variable along with something like the Header to get what you need. |
|
#5
|
|||
|
|||
|
Quote:
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. |
|
#6
|
||||
|
||||
|
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]. |
|
#7
|
|||
|
|||
|
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. |
![]() |
| Viewing: Dev Shed Forums > System Administration > Apache Development > IE choking on directory indexes served as xhtml |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|