0

ユーザーをexample.com/またはwww.example.comからnew.example.comにリダイレクトするにはどうすればよいですか。

しかし、私は次のような特定のURLをリダイレクトしたくありません:

www.example.com/test.php
api.example.com/testo.php
www.example.com/forum/index.php

やった:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule ^(.*)$ http://new.example.com/$1 [R=301,L]

しかし、URLのルールは何ですか?

4

1 に答える 1

0

これを行う 1 つの方法は、.htaccess ファイルの早い段階で、自分自身にリダイレクトする (内部的に、3XX 応答を使用しない) 特定の URL に対して追加のルールを作成し、L フラグを使用して、それらの URL に対して後のルールが処理されないようにすることです。 .

例えば:

RewriteEngine on

# don't redirect these
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule ^(/test.php)$ \1 [L]

RewriteCond %{HTTP_HOST} ^api.example.com$
RewriteRule ^(/testo.php)$ \1 [L]

RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule ^(/forum/index.php)$ \1 [L]

# redirect these
RewriteCond %{HTTP_HOST} ^example.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule ^(.*)$ http://new.example.com/$1 [R=301,L]

「リダイレクトしない」要件にホスト名が含まれているかどうかはわかりません。そうでない場合は、 RewriteCond 行を削除してください。

于 2009-09-03T17:41:50.113 に答える