Help with specific redirect to https

Antonio P.P. Almeida appa at perusio.net
Wed Dec 12 16:48:59 UTC 2012


> I'm trying to redirect anyURL that contains "UserLogin" (ie: Mediawiki) to
> https.  This is what I've tried:
>
> rewrite .*UserLogin.* https://domain.com$request_uri? permanent;
> ----
> rewrite UserLogin https://domain.com$request_uri? permanent;
> ----
> rewrite ^.*UserLogin.*$ https://domain.com$request_uri? permanent;
> ----
>   location ~* .*UserLogin.* {
>     return 301 https://domain.com$request_uri;
>   }
> ----
>   location ~ .*UserLogin.* {
>     return 301 https://domain.com$request_uri;
>   }

At the http level:

map $uri $redirect_https {
    default 0;
    ~^.*UserLogin.*$ 1;
}

Then at the server level do:

if ($redirect_https) {
   return 301 https://$host$request_uri;
}

--appa



More information about the nginx mailing list