2

私がやろうとしていること:

ファイルが存在しない場合は、ファイルへのリクエストを別のドメインにリダイレクトする必要があります。例えば:

http://www.mydomain.com/js/foo.js 

にリダイレクトします(存在しない場合)

http://www.myanotherdomain.com/js/foo.js

私がやること:

htaccessの最後に次の行を書きましたが、すべてリダイレクトされます。

RewriteCond %{REQUEST_URI} !-f
RewriteRule ^(.*)$ http://www.myanotherdomain.com/$1 [L,NC]  

これらの行の前に、次のような行がたくさんあります(MVC(Model、View、Controller)を使用しています):

RewriteRule ^car/brand/?$ ?controller=Car&action=viewBrand [L,NC]  

何が起こるのですか:

存在しないファイルではうまく機能しますが、MVCルールとは互換性がないようです。de "L"フラグがあるため、これらのルールは一致してからルールの評価を停止する必要があります。しかし、ルールの評価を継続し、最終的にリダイレクトルールを評価しているようです。結果は次のとおりです。

http://www.mydomain.com/car/brand/

に行く

http://www.myanotherdomain.com/?controller=Car&action=viewBrand

誰か助けてもらえますか?

どうもありがとうございます、

ジョナサン

4

2 に答える 2

1

これを試して:

RewriteCond %{REQUEST_FILE} !-f
RewriteRule ^(.*)$ http://www.myanotherdomain.com/$1 [QSA,R,L]

参照:ファイル/フォルダーが見つからない場合は、mod rewrite directory

于 2012-10-05T14:57:01.327 に答える
0

Try placing these rules after your MVC rules:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.(js|png|jpe?g|gif|css|html?)$ http://www.myanotherdomain.com/$1.$2 [L,R,NC]

If you want all requests, and not just static content like scripts and images then change the RewriteRule line to:

RewriteRule ^(.*)$ http://www.myanotherdomain.com/$1 [L,R,NC]
于 2012-10-05T20:09:45.363 に答える