Right now I have a line redirecting anything ending in /amp/ to the URL with amp/ removed (since I installed an AMP plugin a while back and then deleted it and am now preventing 404s).
Now I am installing AMP again but want to only have it functioning for pages that have /news/ within them like:
https://www.examplesite.com/news/name-of-article/
so if it has /news/ within the URL, it should allow /amp/ to work and not do a redirect:
https://www.examplesite.com/news/name-of-article/amp/
If it doesn't have /news/ it shouldn't allow /amp/ and should remove /amp/ from the trailing end of the URL.
Right now I have this in my config file to remove /amp/ at all times:
rewrite ^(.*/)amp/$ $1 permanent;
What would be the correct rewrite to make it work the new way and allow /amp/ if /news/ is found within the URL?
You can use a negative lookahead assertion in the regular expression to discard matches that begin with the /news/
string.
For example:
rewrite ^(?!/news/)(.*/)amp/$ $1 permanent;
See this documenmt for details.