1

私はこの動的なルールを持っています:

RewriteRule ^(.*)/(.*)$ /rewrite.php?sub=$1&second=$2 [NC]

そして私はこのようないくつかの静的ルールを追加しようとしています:

RedirectMatch 302 /construction/pools.html http://www.{samedomain}.com/construction-services/pools

問題は、アドレスバーに次のように入力した場合です。

http://www.{samedomain}.com/construction/pools.html

次に、apacheは次の場所にリダイレクトします。

http://www.{samedomain}.com/construction-services/pools?sub=construction&second=pools.html

私が欲しいのは、apacheが次の場所にリダイレクトすることです。

http://www.{samedomain}.com/construction-services/pools

誰かが理由を知っていますか?

ありがとうございました。

4

2 に答える 2

1

リダイレクトは表示された順序で処理されるため、静的リダイレクトをの前に配置するように機能する必要がありRewriteRuleます。[L]あなたの旗を手に入れてはいけませんRewriteRule

RewriteEngine On
# Match the static redirect first
RedirectMatch 302 /construction/pools.html http://www.{samedomain}.com/construction-services/pools

# Since your dynamic URLs don't end in .html, avoid those with RewriteCond
RewriteCond %{REQUEST_URI} !\.html$
RewriteRule ^([^/]+)/(.*)$ /rewrite.php?sub=$1&second=$2 [NC,L]

またはRewriteCond、動的URLのいずれにもがない場合は、それを行うことができます。.

RewriteRule ^([^/]+)/([^.]+)$ /rewrite.php?sub=$1&second=$2 [NC,L]
于 2013-01-17T12:33:34.540 に答える
1

優先度に基づいてhtaccessルールを作成します(最後に共通の動作を持つルールを配置します)

あなたの場合

RedirectMatch 302 /construction/pools.html http://www.{samedomain}.com/construction-services/pools
RewriteRule ^(.*)/(.*)$ /rewrite.php?sub=$1&second=$2 [NC]
于 2013-01-17T12:36:59.577 に答える