mercredi 3 avril 2019

nginx match a folder in path and with no .html which needs to rewrite with .html appended

I have a URL which contains subfolders in the path and may or may not contain .html.

e.g. https://www.example.com/store/test/en/test/ANYCATEGORY/ANDCATEGORY/OPTIONALCATEGORY/PROGRAMNAME/p/100002020

I want to match if the url contains "/p/" in the path AND there is no .html at the end. If these conditions are met, I want to append with .html

e.g. https://www.example.com/store/test/en/test/ANYCATEGORY/ANDCATEGORY/OPTIONALCATEGORY/PROGRAMNAME/p/100002020

I have tried with if statements and location but no luck with any of those.

This is what I have tried with no luck:

    if ($uri ~ ^(.*)/p/(.*)$){
      rewrite ^(.+)/$ $1.html permanent;
    }

    if ($uri ~ ^(.*)/p/(.*[^.html])$){
      rewrite ^(.+)/$ $1.html permanent;
    }

  location ~ ^(.*)/p/(.*[^.html])$ {
      rewrite ^(.+)/$ $1.html permanent;
  }

Aucun commentaire:

Enregistrer un commentaire