1

I have a virtual host like below for my Yii website

server {
        root /var/www/code;
        index  index.php index.html;
        server_name example.com;
        location / {
           rewrite ^/en/keyword$ /en/spesfic_controller/ last;
           ....
         }
}

if i use last or break in the above rewrite rule, nginx throws 404 error, but if i change it to permanent, it will redirect it and will work fine!! what might be wrong? or what i missed? (nothing in error log)
EDIT
the full virtual host is below:

server {
    listen       80;
        root /var/www/code;
        index  index.php index.html;
server_name example.com;
location / {
        rewrite ^/[/]*$ /ar/ permanent;
        proxy_set_header Accept-Encoding "";
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        if (!-e $request_filename) {
                rewrite ^/(.*)$ /index.php?q=$1 last;
                }
        }
        rewrite ^/en/jobs-in-riyadh$ "/en/jobs/SearchResult/city_id/a:1:%7Bi:0;s:2:%2210%22;%7D" last;

        error_log /var/log/nginx/error.log warn;
        access_log /var/log/nginx/access.log;
        if ($http_user_agent ~ libwww-perl) {
              return 403;
        }
        location ~* ^.+\.(jpg|jpeg|gif|css|png|js|ico|ttf|woff)$ {
                access_log        off;
                log_not_found     off;
                expires          max; #you can set it to something like 30d;
                add_header Pragma public;
                add_header Cache-Control "public"; #you can set more than one COMMA seperated ", must-revalidate, proxy-revalidate";
        }
        location ~ \.php$ {
                include /etc/nginx/fastcgi_params;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param  SCRIPT_FILENAME  /var/www/code/$fastcgi_script_name;
                fastcgi_buffer_size 4k;
                fastcgi_buffers 256 4k;
                fastcgi_max_temp_file_size 0;
                proxy_buffering off;
                send_timeout 180s;
                proxy_read_timeout 120s;
                proxy_connect_timeout 120s;
                fastcgi_send_timeout 120s;
                fastcgi_read_timeout 120s;
                fastcgi_connect_timeout 120s;
        }
        location ~ /\. {
            access_log off;
            log_not_found off;
            deny all;
        }
}
  • 1
    Something else is going on. Show the complete server block. – Michael Hampton Dec 7 '14 at 14:22
  • @MichaelHampton ,, Question has been edited – Alaa Alomari Dec 7 '14 at 21:28
  • Is it the /ar/ rewrite? Or the index.php one? – wurtel Dec 8 '14 at 10:43
  • i think the problem is in rewrite ^/(.*)$ /index.php?q=$1 last; – Alaa Alomari Dec 8 '14 at 12:18

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.