1

Webアプリケーションに現在の状況があります。

htmlファイルは、たとえば{currentpath} /images/から画像を要求します

MVCを使用しているため、URLが頻繁に変更されます。

domain.com/app/main/welcome/

(メインクラスからwelcomeメソッドを取得するため)

この状況では、ビューはからの画像を要求します

domain.com/app/main/welcome/images/

どのような状況でも、スクリプトがその画像サブフォルダーから何かを要求した場合、固定フォルダー(たとえば、domain.com / app / images /)にリダイレクトする必要があります。

これまでのところ、私はこれを試しました:

RewriteRule ^(.*)/app/(.*)/images/(.*)$ $1/app/images/$3 [R=301,L,QSA]

これは機能しません。

私の意図はリダイレクトすることです:

domain.com/app/{anything}/images/ 

domain.com/app/images/{the requested image}

これはstackoverflowでの私の最初の投稿であり、通常は検索ですべての答えを直接見つけますが、これについてはどうすればよいかわかりません。

ところで、固定パスを使用してすべてのビューでreplace_allを実行できることはわかっていますが、将来変更される可能性があるため、これははるかにエレガントな方法になります。

4

2 に答える 2

0

You can try:

RewriteRule ^/?app/.+/images/(.*)$ /app/images/$1 [R=301,L,QSA]

You might want to decide on how you want the urls to permanently be though and just change the redirects to match and just change the rest in the background. You might want to consider Alias as well:

... where {currentpath} has to be filled in

Alias /app/{currentpath}/images /app/images

or AliasMatch

AliasMatch ^/app/.+/images(.*) /app/images$1

and then change the last part when the folder changes, you can also permanently redirect through mod_alias although it's a little different:

Redirect 301 /app/{currentpath}/images http://domain.com/app/images

There is also a RedirectMatch as well.

See: http://httpd.apache.org/docs/2.0/mod/mod_alias.html

于 2012-04-27T20:56:25.583 に答える
0

必要なルールは次のとおりです。

RewriteRule ^(app/)[^/]+/(images/.*)$ $1$2 [R=301,L,NC]
于 2012-04-27T21:51:51.060 に答える