Why rewrite directive causes "301 Moved Permanently" with Nginx?

Posted by Desmond Hume on Ask Ubuntu See other posts from Ask Ubuntu or by Desmond Hume
Published on 2012-12-05T21:45:35Z Indexed on 2012/12/05 23:19 UTC
Read the original article Hit count: 377

Filed under:
|
|

Below is a much simplified version of what I have in the configuration file of a server run by Nginx 1.2.5, yet it causes 301 Moved Permanently with Location: http://example.com/phpmyadmin/ before serving data, which is not what I expected from the default behavior of the rewrite directive.

server {
    listen 80;
    location /pma {
        rewrite ^ /phpmyadmin;
    }
    location /phpmyadmin {
        root /var/www;
        index Documentation.html;
    }
}

When I follow http://example.com/pma, the data is served but the URL in the browser is changed to http://example.com/phpmyadmin/ while it was supposed to stay http://example.com/pma.

How do I avoid Nginx sending 301 Moved Permanently so that it doesn't expose the actual directory structure on my server?

© Ask Ubuntu or respective owner

Related posts about webserver

Related posts about nginx