3

2 つのドメイン (VirtualHost 経由) を持つ Apache サーバーがあります。
ファイルのセットアップは次のようになります。 /example1/example2/
example1is the root for www.example1.com
example2is the root for www.example2.com
I would like www.example1.com/example2/<whatever else>to redirect to www.example2.com/<whatever else>
I have access to the main Apache configuration file. これを行う方法に関するヒントはありますか?私は Apache の設定にあまり詳しくないので、どんな説明でも大歓迎です。

これに関連する他の質問には説明が欠けていたので、自分の質問を投稿する必要があると感じました.

4

2 に答える 2

5

.htaccess ファイルを使用すると、これを非常に迅速に行うことができます。ではwww.example1.com/example2/、この .htaccess ファイルを作成します。

<VirtualHost *:80>
    ...
    <Directory /path/to/vhost/>
      RewriteEngine on
      RewriteBase /example2/
      RewriteRule ^(.*)$ http://www.example2.com/$1 [R=301]
    </Directory>
</VirtualHost>

example2これは、リダイレクトを 301 にする必要があり、フォルダーがAllowOverride All設定されていることを前提としています。

このルールは、正規表現を使用して着信 URL をキャプチャし、example2ビットを削除してから、書き換えられた URL に追加します。R角括弧内の は、書き換えられた URL に Location ヘッダーを使用するように Apache に指示します。は=301、Apache に 301 Permanent Redirect ヘッダーを使用するように指示します。

于 2012-04-21T22:21:32.677 に答える
4

mod_aliasアクティブにする場合は、Redirect ディレクティブを使用できます

<VirtualHost *:80>
    ServerName example1.com
    Redirect 301 /example2 http://www.example2.com
</VirtualHost>
于 2013-06-28T17:46:24.580 に答える