1

I'm trying to make redirect on nginx but unfortunately it doesn't work. What I'd like to achieve, it is to redirect amp files on mobile.

What I'd like to do :

from

https://www.example.com/uri-759.html

to

https://www.example.com/uri-759-amp.html

What I did as redirect

if ($mobile_redirect = perform) {

    redirect ^(.*)(\.html)$ $1-amp$2 permanent;
}

what I obtain

https://www.example.com/uri-759-amp-amp-amp-amp-amp-amp-amp-amp.html

Does someone have a solution to perform this redirection ?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
JBRLANTS
  • 63
  • 1
  • 7

1 Answers1

2

You can use a negative lookbehind assertion to avoid matching the rewritten URI.

For example:

rewrite ^(.*)(?<!-amp)(\.html)$ $1-amp$2 permanent;

See this document for more.

Richard Smith
  • 45,711
  • 6
  • 82
  • 81