A
A
Anton Artyomov2015-10-22 18:58:55
Nginx
Anton Artyomov, 2015-10-22 18:58:55

How to redirect some pages in ngninx?

Good to everyone. I've looked all over the internet and haven't found an answer yet. How to redirect a page with a specific get parameter to another schema.
It is required to open 2 pages of the site only via https. The entire site is http.
these pages
http://mysite/component/content/article.html?id=71
http://mysite/component/content/article.html?id=72
It is necessary that only 301 redirects to the https protocol work on them.
What I have tried:

if ($scheme = 'http' ) {
        rewrite	/component/content/article.html?id=71$  https://мойсайт/component/content/article.html?id=71 permanent;
    }

It seems that rewrite does not see the parameters. And he sees them only if you enter instead of them, for example (.*) in the redirect address, specify $1

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex, 2015-10-22
@ArtyomovAnton

You need to write locationinside the section serverthat listens on the 80th port. In locationyou need to check the get parameter.

server {
    listen 80;

    location ~* /component/content/article.html {
        if ($args ~ "^id=(71|72)") {
            return 301 https://мойсайт$request_uri;
        }
    }
    # всякие ваши настройки
}

I wonder why all of a sudden these two pages, which differ from the others only by id, needed to be taken out? Maybe it's better to put them in a separate path? Type /private/component/content/article.htmland already for /privatealways do a redirect to HTTPS?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question