aris
December 12, 2012, 5:14pm
1
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;
}
All of them have no effect. I’m running out of trial to match my error.
Can anyone tell me what I’m doing wrong? Thank you.
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
On Wed, Dec 12, 2012 at 09:13:27AM -0700, Pete Ashdown wrote:
Hi there,
I’m trying to redirect anyURL that contains “UserLogin” (ie: Mediawiki) to
https. This is what I’ve tried:
Can you show one example request that you would like to have redirected?
In nginx, the query string part of the request may not be matched when
you might expect it to be.
f
Francis D. [email protected]
On 12/12/2012 09:48 AM, Antonio P.P. Almeida wrote:
return 301 https://domain.com$request_uri;
}
Then at the server level do:
if ($redirect_https) {
return 301 https://$host$request_uri;
}
Thanks for your attempt, but this failed as well.
Pete
Thanks for your attempt, but this failed as well.
What’s the exact structure of your URI?
If it’s an argument then there are several approaches. For starters this
should work (but it’s ugly to improve it we need further details).
map $request_uri $redirect_https {
default 0;
~*^.UserLogin. $ 1;
}
–appa
On 12/12/2012 11:07 AM, Antonio P.P. Almeida wrote:
}
This is what it looks like via Mediawiki. The &returnto argument is
dependent on where the Login button is hit, and may or may not be
present.
http://domain.com/index.php?title=Special:UserLogin&returnto=Main+Page
On Wed, Dec 12, 2012 at 12:22:51PM -0700, Pete Ashdown wrote:
Hi there,
This is what it looks like via Mediawiki. The &returnto argument is
dependent on where the Login button is hit, and may or may not be present.
Domain.com
In nginx terms, for this request, $uri = /index.php. $uri is what both
“rewrite” and “location” match against. That is why the first few
attempts
did not do what you hoped they would.
Some other variables which are available include:
$request_uri = /index.php?title=Special:UserLogin&returnto=Main+Page
$args = title=Special:UserLogin&returnto=Main+Page
$arg_title = Special:UserLogin
So you can do an exact or regex match of any of those in a “map” to set
another variable; or you can match directly in an “if”; and then return
the redirection.
All the best,
f
Francis D. [email protected]
On 12 Dez 2012 20h22 CET, [email protected] wrote:
default 0;
~*^.UserLogin. $ 1;
}
This is what it looks like via Mediawiki. The &returnto argument is
dependent on where the Login button is hit, and may or may not be
present.
Domain.com
Try:
map $arg_title $redirect_https {
default 0;
Special:UserLogin 1;
}
— appa
On 12/12/2012 03:30 PM, Antnio P. P. Almeida wrote:
map $request_uri $redirect_https {
map $arg_title $redirect_https {
default 0;
Special:UserLogin 1;
}
Thank you Antonio. This works perfectly.