次の行は、実際には EXTERNAL リダイレクトを強制します。
RewriteRule ^(.*)$ http://localhost/gallery/$1 [R=301,L]
そのため、へのリクエストhttp://localhost/foobarは 301 レスポンスになり、クライアントに をリクエストするように伝えますhttp://localhost/gallery/foobar。クライアントが に新しいリクエストを送信するhttp://localhost/gallery/foobarと、 に 301 応答が返さhttp://localhost/gallery/gallery/foobarれます。
代わりにこれを試してください:
AddDefaultCharset UTF-8
Options +FollowSymlinks -Indexes
RewriteEngine On
RewriteCond %{THE_REQUEST} /index\.(php|html)\ HTTP/
RewriteRule ^index\.(php|html)$ / [R=301,L]
RewriteCond %{REQUEST_URI} !^/gallery/
RewriteRule ^(.*)$ http://localhost/gallery/$1 [R=301,L]
RewriteBase /
RewriteRule ^gallery/([^.]+)/?$ gallery/index.php?url=$1 [NC,QSA,L]
無限ループ ルールの前に書き換え条件を追加して、すでに /gallery で始まる URL がそのリダイレクトをアクティブにしないようにしていることに注意してください。
また、ご指摘のとおりに適切に書き直すようにファイル ルールを修正しましhttp://localhost/gallery/foobarたhttp://localhost/gallery/index.php?url=foobar。/?このパターンの はオプションの末尾のスラッシュを提供するため、http://localhost/gallery/12とhttp://localhost/gallery/12/の両方が機能することに注意してください。後者が必要ない場合は/?、パターンから を削除します。