Answer the question
In order to leave comments, you need to log in
How to properly rewrite in Nginx?
Hello super community.
Tell me please.
I want to make it so that users accessing the site from a smartphone
see AMP pages, but at the same time, if they go to the main page, then it is given without the /amp prefix.
That is, you need this:
examle.ru -> examle.ru
but
examle.ru /post-1/ -> examle.ru/post-1/amp
examle.ru/page-3/ -> examle.ru/page-3/amp
Now in nginx like this:
if ($mobile_rewrite = perform) {
rewrite ^(.*(?<!/amp))/$ https://$server_name$1/amp/ break;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question