views:

28

answers:

1

Hello, as the title says, I want to use an xhtml as my homepage and I want to redirect visitors using Internet Explorer browsers to a different page (a .htm with less content that says "You're using IE, tough tittie.").

Since IE automatically downloads app/xhtml files, I can't do this using javascript and whatnot, so I think the only option is to use .htaccess. But after almost 2 hours of googling htaccess examples from similar posts, I still can't get it to work, I get either 403 or 500 both in IE and in chrome/firerfox..

Here's what I tried last:

<IfModule mod_rewrite.c>
Options +FollowSymLinks 
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_USER_AGENT} "MSIE 5" [OR]
RewriteCond %{HTTP_USER_AGENT} "MSIE 6" [OR]
RewriteCond %{HTTP_USER_AGENT} "MSIE 7" [OR]
RewriteCond %{HTTP_USER_AGENT} "MSIE 8"
RewriteRule ^(.*)$ http://www.mypage/index.IE.htm
</IfModule>

Anyway, to to make this clearer, I'd like my .htaccess to do this:

if(whoever_accesses_my_page is anyVersionOf_IE)
     set_index("http://www.mypage/index.IE.htm");
else
     set_index("http://www.mypage/index.xhtml");
A: 

After A LOT of hit and miss (probably since I don't know .htaccess) I've figured it out:

RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} .*MSIE.*
RedirectMatch ^/$ index.IE.htm
DirectoryIndex index.xhtml

The above snippet will have effect when someone visits "http://www.yoursite.com/optionalFolder/". It will redirect from there, to index.IE.htm if the visitor is any form of Internet Explorer over version 4, else (if you're not IE) go to index.xhtml.


I have also found a neat trick to get Internet Explorer to actually read the same .xhtml as Text/HTML, so you won't have to maintain 2 separate versions of the same site:

RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} .*MSIE.*
RewriteCond %{REQUEST_URI} \.xhtml$
RewriteRule .* - [T=text/html]

This snippet has effect when someone accesses "http://www.yoursite.com/anyPageName.xhtml". If it's Internet Explorer, then it will overwrite the document type to text/html instead of application/xhtml+xml. Else, any other browser will open the xhtml normally.


Question: How can I get snippet #2 to work for a URL that has just the directory path?

(it only works for "http://www.yoursite.com/pageName.xhtml"; how can I get it to work for "http://www.yoursite.com/optionalFolder/"?)

In other words, DirectoryIndex index.xhtml doesn't work in snippet #2 (it overpowers the RewriteRule for IE; if I add DirectoryIndex, IE will auto-download the xhml)

Twodordan