ディスク上の私のファイルは、拡張子がindex.html
,a.html
です。 http://example.com/a
に/var/www/a.html
とhttp://example.com/
をロードして/var/www/index.html
をロードするリクエストが必要です。標準URLにリダイレクトする他のURLが必要なので、http://example.com/a.html
はhttp://example.com/a
にリダイレクトする必要があります。/foo/foo.htmlをnginxの/ to/indexにリダイレクト
私の設定は次のようになります。これは/a
に/a.html
をリダイレクトし、ディスクからロードa.html
で成功し
rewrite ^(/.+)\.html$ $scheme://$host$1 permanent;
location/{
root /var/www;
try_files $uri.html $uri $uri/ =404;
}
:
$ curl -D- -s http://www.jefftk.com/food.html | grep ^Location
Location: http://www.jefftk.com/food
$ curl -s http://www.jefftk.com/food | grep ^Location
しかし、それは/index
に/
を送信します。
$ curl -s -D- http://www.jefftk.com/pictures/ | grep ^Location
Location: http://www.jefftk.com/pictures/index
$ curl -s -D- http://www.jefftk.com | grep ^Location
Location: http://www.jefftk.com/index
私は書き換えルールを削除すると、それは/a
に/a.html
からリダイレクトするだけでなく、/index
に/
の送信を停止し停止します。
$ curl -D- -s http://www.jefftk.com/food.html | grep ^Location
$ curl -D- -s http://www.jefftk.com/food | grep ^Location
$ curl -D- -s http://www.jefftk.com/ | grep ^Location
$ curl -D- -s http://www.jefftk.com/pictures/ | grep ^Location
これはなぜ起こるのでしょうか?私は両方のnginxを作ることができます(いいえ.html
の拡張子、いいえ、index
のURLで)?
これは 'http:// example.com/file.html'を' http:// example.com/file'にリダイレクトしません。 –
申し訳ありませんが、私はあなたの質問を完全に理解していませんでしたが、もう一度読み直していくつかの新しいルールをテストしました。上記のコードを修正して追加の場所を追加しました。 – kchan
これはうまくいきませんでした。/ fooは/ foo/indexにリダイレクトされますが、 –