Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've written a small htaccess file to redirect Internet Explorer users to a specific page Here are the contents :

# MS Internet Explorer - Mozilla v4
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} ^Mozilla/4(.*)MSIE
RewriteRule ^index\.php$ /sorry.php [L]

# All other browsers
#RewriteRule ^index\.html$ /index.32.html [L]

Any clue why this would give a 500 Internal Server Error ? I have used mod rewrite before so i have the module loaded there...

share|improve this question

migrated from stackoverflow.com Nov 24 '11 at 0:21

This question came from our site for professional and enthusiast programmers.

Are there any hints in Apache's error logs? – awendt Nov 14 '11 at 10:08
i checked on the server in my logs folder, tho there are no files there i have no clue why (im hosted with Godaddy) and i have access via SSH if that helps.. – Dany Khalife Nov 14 '11 at 15:49
do both sorry.php and index.32.html exist? Are they in the right directory? Is this for a base level page or for a page somewhere deep inside a directory structure? – Mike 'Pomax' Kamermans Nov 18 '11 at 1:28
only sorry.php exist (the line for index.32) is commented out.... and this is at the root, nothing else there (for now) – Dany Khalife Nov 18 '11 at 1:30
replace sorry.php with a normal .html page and see if it still throws an error. PHP is known to cause "500" errors when it has terminal errors. – Mike 'Pomax' Kamermans Nov 18 '11 at 2:04

Please try to use the RewriteLog directive: it helps you to track down such problems:

# Trace:
# (!) file gets big quickly, remove in prod environments:
RewriteLog "/web/logs/mywebsite.rewrite.log"
RewriteLogLevel 9
RewriteEngine On

Then tell me as a comment what it gives and I'll update my answer to help you.

share|improve this answer
i've been also fighting with logs, can't seem to get some lately, especially from php's, but i'll give your code a shot tomorrow and let you know :) – Dany Khalife Nov 19 '11 at 3:18
i finally got a good reply from support and fixed the problem, tho i didn't need this, i'll keep it in mind for future debug +1 – Dany Khalife Nov 20 '11 at 3:48

It works for me, I changed ^Mozilla/4(.)MSIE to !^Mozilla/4(.)MSIE to test it with any other browser. Normally a HTTP 500 error when modifing your htaccess means that something is incorrect with the htaccess file. Copied from apache manual at http://httpd.apache.org/docs/2.0/misc/rewriteguide.html

RewriteCond %{HTTP_USER_AGENT}  ^Mozilla/4.*
RewriteRule ^foo\.html$         foo.NS.html          [L]

Some apache versions or installations do not like redirects without a full url: (one server I work on)

RewriteRule ^index\.php$ http://www.example.com/sorry.php [L]

Different browser selections could be written like below:

# Mozilla 4/5 Browsers 
RewriteCond %{HTTP_USER_AGENT} ^Mozilla/[4-5]\.[0-9]+\ \(compatible;\ MSIE\ [3-9]\.[0-9.]+
RewriteCond %{HTTP_USER_AGENT} ^Mozilla/[4-5]\.[0-9]+\ \(Macintosh;\ .+\)\ \AppleWebKit/[1-9]\.[0-9.]+\ \(KHTML,\ like\ Gecko\)\ \Safari/[0-9]{3,8}$
RewriteCond %{HTTP_USER_AGENT} ^Mozilla/[4-5]\.[0-9]+\ \(Macintosh;\ I;\ PPC\)$ 
RewriteCond %{HTTP_USER_AGENT} ^Mozilla/[4-5]\.[0-9]+\ \(X11;\ U;\ Linux\ i686;\ [a-z]{2}-[A-Z]{2};\ rv:[1-9]\.[0-9.]+\)\ Gecko/Debian-[1-9]\.[0-9.]+-[0-9]+\ Galeon/[2-9]\.[0-9.]+\ \(Debian\ package\ [2-9]\.[0-9.]+-[0-9]+\)$ 
RewriteCond %{HTTP_USER_AGENT} ^Mozilla/[4-5]\.[0-9]+\ \(compatible;\ Konqueror/([0-9]+\.)+[0-9]+.+\ 20[0-9]{6}\)$ 
RewriteCond %{HTTP_USER_AGENT} ^Mozilla/[4-5]\.[0-9]+\ \(compatible;\ Konqueror/([0-9]+\.)+[0-9]+;\ Linux\)\ \(KHTML,\ like\ Gecko\)$ 
RewriteCond %{HTTP_USER_AGENT} ^Mozilla/[4-5]\.[0-9]+\ \(.+;\ rv:([0-9]+\.)+[0-9a-z]+\)\ Gecko/20[0-9]{6} 
RewriteCond %{HTTP_USER_AGENT} ^Mozilla/[4-5]\.[0-9]+\ WebTV/([0-9]+\.)+[0-9]+\ \(compatible;\ MSIE\ [5-9]\.[0-9]+ 
# Others 
RewriteCond %{HTTP_USER_AGENT} ^Avant\ Browser\ \(http://www\.avantbrowser\.com\)$ 
RewriteCond %{HTTP_USER_AGENT} ^Microsoft\ Internet\ Explorer/[34]\.[0-9]{1,2} 
RewriteCond %{HTTP_USER_AGENT} ^Mozilla/(3\.01¦4\.0)\ \(compatible;\)$ 
RewriteCond %{HTTP_USER_AGENT} ^Mozilla/[3-4]\.[0-9]+\ \[[a-z]{2}\](\ \(.+\))? 
RewriteCond %{HTTP_USER_AGENT} ^Mozilla/4\.0\ \(PSP\ \(PlayStation\ Portable\);\ [0-9.]+\)$ 
RewriteCond %{HTTP_USER_AGENT} ^Opera/[5-9]\.[0-9]+ 
share|improve this answer
lol thats a bit overkill for what i am trying to do tho i'll leave it for later thanks :) – Dany Khalife Nov 19 '11 at 3:16
up vote 1 down vote accepted

I finally got a good reply from support Looks like, for some reason, i need to have RewriteBase / in every .htaccess that uses mod rewrite in order for that module to work correctly, idk why but that seems to fix the problem Thanks for all the great comments tho :)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.