Nginx の書き換え: 引数付きの URL から .html を削除する

Nginx の書き換え: 引数付きの URL から .html を削除する

引数付きの URL から .html を削除するにはどうすればよいですか?

例えば: http://www.domain.com/somepage.html?argument=whole&bunch=a-lot

に:

http://www.domain.com/somepage?argument=whole&bunch=a-lot

私が試してみました

    location / {
    index index.html index.php; 
            rewrite ^\.html(.*)$ $1 last;
            try_files $uri $uri/ @handler; 
            expires 30d; ## Assume all files are cachable
     }

他にもたくさんの提案をしましたが、うまくいかないようです...

ありがとう

答え1

次のように構成を変更します。

# rewrite html extensions
rewrite ^(/.+)\.html$ $scheme://$host$1 permanent;

location / {
    index index.html index.php;
    # this way nginx first tries to serve the file as an .html although it doesn't have the extension
    try_files $uri.html $uri $uri/ @handler;
}

もちろん、キャッシュ設定などを追加することもできますが、.html 部分を削除するにはこれで十分です。

関連情報