2

/healthへのパスを書き換えたい/health.php

私は現在、キャッチオールルールで次の.htaccessファイルを持っています:

RewriteEngine On
RewriteRule ^.*$ index.php [L]

そこで、キャッチオールの前に新しいルールを追加しました。

RewriteEngine On
RewriteRule ^health$ health.php [L]
RewriteRule ^.*$ index.php [L]

しかし、驚いたことに、ブラウザでhealth.phpリクエストしたときに書き換えられません。/health

ただし、最後の (キャッチオール) ルールを削除すると、期待どおりに機能します。

[L]mod_rewrite がルールをフラグと一致させた後、ルールの処理を停止しないのはなぜですか?

4

1 に答える 1

5

それを見つけた。[L]フラグがすべてのルールの処理を停止したといつも思っていました。実際には、現在のルールセットのルールの処理を停止するだけで、書き換えられた request でルールセット全体を再実行します

したがって、書き換えログが示すように、私のキャッチオール コードは最終的にそれをキャッチしていました。

strip per-dir prefix: [...]/public/health -> health
applying pattern '^health$' to uri 'health'
rewrite 'health' -> 'health.php'
add per-dir prefix: health.php -> [...]/public/health.php
strip document_root prefix: [...]/public/health.php -> /health.php
internal redirect with /health.php [INTERNAL REDIRECT]

strip per-dir prefix: [...]/public/health.php -> health.php
applying pattern '^health$' to uri 'health.php'
strip per-dir prefix: [...]/public/health.php -> health.php
applying pattern '^.*$' to uri 'health.php'
rewrite 'health.php' -> 'index.php'
add per-dir prefix: index.php -> [...]/public/index.php
strip document_root prefix: [...]/public/index.php -> /index.php
internal redirect with /index.php [INTERNAL REDIRECT]

strip per-dir prefix: [...]/public/index.php -> index.php
applying pattern '^health$' to uri 'index.php'
strip per-dir prefix: [...]/public/index.php -> index.php
applying pattern '^.*$' to uri 'index.php'
rewrite 'index.php' -> 'index.php'
add per-dir prefix: index.php -> [...]/public/index.php
initial URL equal rewritten URL: [...]/public/index.php [IGNORING REWRITE]

このブログにある解決策では、キャッチオール ルールの前に条件を配置して、以前に内部リダイレクトが処理されていない場合にのみ実行します。

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^.*$ index.php [L]
于 2013-08-05T22:54:26.750 に答える