I want to optimize the link structure of an older Magento shop system. Until now, when generating the static pages, a .html suffix was added to the corresponding path. Due to an earlier problem, paths with double suffixes even existed (e.g. .html.html). Now that I have disabled the use of suffixes and deleted all paths with double suffixes from the database, I want to set up automatic redirections from the old URLs to the new ones.
To preserve existing hyperlinks and search engine entries, I want Nginx to redirect all requests for pages with a .html or .html.html suffix to the new path.
Requests to:
example.org/banana.html
example.org/banana.html.html
should be redirected to:
example.org/banana
so actual my best guess is:
location / {
rewrite ^(.*?)\.html(\.html)?$ $1 permanent;
try_files $uri $uri.html $uri.html.html $uri/ =404;
}
How do I reach my goal and what rewrite rules do I need to add to the nginx configuration?