Trouble adding /pma location to all virtual hosts

Ben Johnson ben at
Thu Jun 27 16:55:22 UTC 2013

On 6/27/2013 12:42 PM, Ben Johnson wrote:
> I'm not the type to accept "good enough". I want it to be perfect :).
> What would be your preferred course of action to eliminate the internal
> rewrite and instead perform an external redirect for /pma, /PMA, and
> /PMA/ (all redirected to /pma/)?
> The documentation states, "There is no syntax for NOT matching a regular
> expression. Instead, match the target regular expression and assign an
> empty block, then use location / to match anything else."
> If I'm not mistaken, the location below would match all of the
> "incorrect" variants that I listed above:
> location ~* /pma {
> }
> But then I'm confused as to where the "return 301 /pma/;" needs to be
> placed, if anywhere.
> To be clear, I have a "normal website" running on this vhost (a
> customer's own site), so I had assumed that I can't use an empty
> location block, as the manual suggests, and fall-back to "location /".
> Somewhat surprisingly, including the above location block actually works
> to redirect /pma, /PMA, and /PMA/ to /pma, while still allowing the
> "normal site content" to function correctly.
> Is this because I have the following directive just before the
> PMA-related bit we've been discussing?
> location / {
>    try_files $uri $uri/ @virtual;
> }
> location @virtual {
>     if ($uri !~ '/$') {
>        return 301 $uri/$is_args$args;
>     }
>     include /etc/nginx/fastcgi_params;
>     fastcgi_pass unix:/var/lib/php5-fpm/web2.sock;
>     fastcgi_index index.php;
>     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
>     fastcgi_intercept_errors on;
>     rewrite  ^(.*)$  /index.php?q=$1  last;
> }

A slight correction to part of my last reply.

The location block that actually worked to redirect requests to
incorrect variants of the /pma URL *did* contain the 301 redirect line:

location ~* /pma {
    return 301 /pma/;

With this block, the "main site" seems to function as expected, and all
of the redirects that I identified previously work as expected.

Is this "incorrect" for any reason?

Thanks again,


More information about the nginx mailing list