Mobile app version of vmapp.org
Login or Join
Dunderdale272

: What's wrong with my htaccess ? (500 Error) I've written a small htaccess file to redirect Internet Explorer users to a specific page Here are the contents : # MS Internet Explorer - Mozilla

@Dunderdale272

Posted in: #BrowserDetecting #Htaccess #HttpCode500 #ModRewrite #Redirects

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

10.03% popularity Vote Up Vote Down


Login to follow query

More posts by @Dunderdale272

3 Comments

Sorted by latest first Latest Oldest Best

 

@Michele947

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

10% popularity Vote Up Vote Down


 

@Alves908

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 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$ 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]+

10% popularity Vote Up Vote Down


 

@BetL925

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.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme