3

index.htmlスラッシュで終わる URLに追加する mod_rewrite ルールは何でしょうか? ルールは、存在するすべてのクエリ文字列を保持する必要があります。ファイルがファイル システムに物理的に存在しないDirectoryIndexため、ディレクティブを使用できませんが、基になる Web サイト フレームワークで必要とされます。index.html

URL の例と目的の結果を以下に示します。

http://example.com/                   -> http://example.com/index.html
http://example.com/?a=1               -> http://example.com/index.html?a=1
http://example.com/foo/               -> http://example.com/foo/index.html
http://example.com/foo/?b=2           -> http://example.com/foo/index.html?b=2
http://example.com/foo/index.html     -> http://example.com/foo/index.html
http://example.com/foo/index.html?c=3 -> http://example.com/foo/index.html?c=3
4

1 に答える 1

7

クエリ文字列自体が変更されていない限り、クエリ文字列は mod_rewrite によって自動的に追加されます。これはあなたが必要とするものです:

RewriteEngine On
RewriteRule ^/?$ /index.html [L,R=301]
RewriteRule ^/?(.*)/$ /$1/index.html [L,R=301]

これにより、誰かが で終わるものを要求したときに/、ブラウザを同じ URL にリダイレクトしますindex.html。空白の URI は特殊なケースです (最初の規則)。ブラウザをリダイレクトする必要がない場合は,R=301、角括弧から を削除してください。

于 2012-09-14T17:37:40.690 に答える