Server Fault is a question and answer site for system and network administrators. 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 am following tutorial.

I have the following configuration.

ancient_browser "MSIE 6.0";

if ($ancient_browser){
  rewrite  ^  /ie6;

the problem with this is that I get an infinity loop.

How do I make it work!? I'm surprised that even an example on an official doc. doesn't work.


My current code

server {

        listen 83;
        server_name {my ip goes here}

        location / {

                ancient_browser "MSIE 6.0";

                if ($ancient_browser){
                        rewrite ^ /ie6 break;

                proxy_pass http://localhost:34881 ;

                proxy_set_header Host $host ;
                proxy_set_header X-Real-IP $remote_addr ;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for ;
                proxy_set_header Country $geoip_country_code;

                proxy_cache cache;
                proxy_cache_valid 200 302 1h;
                proxy_cache_valid 404     1m;
                 add_header Pragma no-cache;
                expires epoch;
                if_modified_since off;
                add_header Last-Modified "";

Update 2:

I came up with the following code snippet and it works.

if ($http_user_agent ~ "MSIE 6.0") {
    set $IE T;              

if ($uri != "/ie6/") {
    set $IE "${IE}RUE";

if ($IE = TRUE) {
    rewrite ^ /ie6 break;

if anyone has a better solution, please leave a comment..thanks!!!

share|improve this question
up vote 4 down vote accepted

Try to use $http_user_agent instead:

if ($http_user_agent ~ "MSIE 6.0" ) {
    rewrite ^ /ie6 break;

or take a look at this topic.

share|improve this answer

Add break:

rewrite ^ /ie6 break;

The intent with the example was probably that the config not be applied in the location that you were rewriting to.

share|improve this answer
// I've added break, but I still have an infinity loop.. – Moon Oct 27 '11 at 22:17

You need to make sure that you redirect the user to a part of the configuration that isn't handled by the same rule.

Does something like this work, perhaps?

location ^/ie6 {
share|improve this answer
// I want to detect browser type and then direct users to /ie6. – Moon Oct 27 '11 at 23:15
That's why you create a seperate block for ^/ie6, that does not have the ancient-browser detection in it :) – Kvisle Oct 28 '11 at 12:39

Your Answer


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

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