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...

  • 1
    Are there any hints in Apache's error logs?
    – awendt
    Nov 14, 2011 at 10:08
  • 1
    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, 2011 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, 2011 at 1:28
  • 1
    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, 2011 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, 2011 at 2:04

3 Answers 3


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.

  • 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, 2011 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, 2011 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]+ 
  • 1
    lol thats a bit overkill for what i am trying to do tho i'll leave it for later thanks :)
    – Dany Khalife
    Nov 19, 2011 at 3:16

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 :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.