1

test.comをtest.com/contextに書き直したい。

ブラウザはリダイレクト再帰エラーを返します。

誰か手がかりがありますか?

以下にhttpd-vhosts.confに入れます。

<VirtualHost *:80>
    ServerName test.com

    JkMount /* mschoi
    ErrorLog logs/mschoi-error_log
    CustomLog logs/mschoi-acces_log common

    RewriteEngine On
    RewriteRule ^/(.*)$ /context/$1 [L,R]

</VirtualHost>

httpd.conf
Include conf/extra/httpd-vhosts.conf
4

1 に答える 1

2

/contextこれは、ルールが書き換えられたときに再び一致する単純なケースです。あなたはRewriteCondそれを避けるためにただaを使うことができます:

RewriteEngine On
# Rewrite only if the request doesn't already match /context
RewriteCond %{REQUEST_URI} !^/context
RewriteRule ^/(.*)$ /context/$1 [L,R]

アクセスされているファイルが(書き換えパターンではなく)実際に存在する場合は、実際に存在するファイルをテストして書き換えることはできません。

RewriteEngine On
# If the requested resource is not actually a real file or directory (doesn't exist)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/(.*)$ /context/$1 [L,R]

コメントの後に編集して説明します。

ディレクトリごとのルールだけでなく、再帰が発生する可能性があります。この場合、/(.*)にでも一致し、無条件にに追加されるのは単純な問題です。リダイレクトするフラグが存在し、これらはそれぞれ新しいリクエストであるため、次のリダイレクトチェーンになります。/content[R]

/something
/content/something
/content/content/something
/content/content/content/something

後続のリダイレクトは、常に先頭とそれに/content続くものおよびそれに続くものと一致し続け/(.*)ます。

于 2013-01-16T14:05:31.660 に答える