2017-08-07 7 views
1

私はこれについてのstackoverflowページと非stackoverflowサイトの束を見て、たくさんのことを試しました。何も働いていません。ルートドメインのみをリダイレクトし、すべてのワイルドカードサブドメインを無視するにはどうすればよいですか?

example.comに行くにはmy-example.netが必要です。example.comに行くにはwww.my-example.netが必要です。私はallothersubdomainsthatarenotwww.my-example.netを無視してリダイレクト。私は将来、特定の他のサブドメインを除外したいかもしれません。そのため、1つの試みに4つのサブドメイン例外がありますが、今はwww以外のすべてのサブドメインを無視することに集中しましょう。 wwwとnon-wwwは別のドメインに移動する必要があります。私たちが残りの経路をそのままにしておくことができれば、2番目のドメインのルートに行くのはいいです。例えば:あなたが知っているだけのよう

http://my-example.net/some/path/file.php?parameter=value can go to http://example.com/some/path/file.php?parameter=value, 
but if it's to difficult with wildcard subdomains, then going to http://example.com/ is fine. 

、私はワイルドカードは、特定の方法をサブドメインとそれが正常に動作扱う場所で他のルールを持っています。いくつかの試みはうまくいくようですが、私がサブドメインに持つ他のルールセットを破ります。たとえば、私はanysubdomain.my-example.netがmy-example.net/folder/file.php?anysubdomainに行くとしましょう。& domain = my-example.net ...次に、以下の試みのどれか1つまたはいくつかを行いますサブドメインがこれを行うのは私の望むものではありません。example.com/folder/file.php?anysubdomain & domain = example.com

サブドメインは、長いパスとメインドメインを持つ自分のドメインにリダイレクトする必要がありますそして、サブドメインがセカンダリドメイン(とやパスの残りの部分を保存せず)にリダイレクトする必要がありますWWWここ

は私の試みです(各ラインのスペースは、新たな試みを意味するが、カップルの試みでは、コメントを解除する必要があり、すべての行ではありません - 私は試行のバリエーションを試していた):

#RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$ 
#RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [L,R=301] 

#RewriteCond %{HTTP_HOST} ^my-example\.net$ 
#RewriteRule ^(.*)$ http://example.com/$1 [L,QSA,R=301] 

#RewriteCond %{HTTP_HOST} ^my-example\.net$ [NC] 
#RewriteRule ^. http://example.com/ [L,R=302] 

#RewriteCond %{HTTP_HOST} ^(my-example\.net)$ [NC] 
#RewriteRule ^. http://example.com/ [L,R=302] 

#RewriteCond %{HTTP_HOST} my-example\.net [NC] 
#RewriteCond %{REQUEST_URI} ^/$ 
#Rewriterule ^(.*)$ http://example.com/ [L,R=301] 

#RewriteCond %{HTTP_HOST} !^www\.example\.com [NC] 
#RewriteCond %{HTTP_HOST} !^$ 
#RewriteRule ^/?(.*)   http://example.com/$1 [L,R,NE] 

#RewriteCond %{HTTP_HOST} ^my-example\.net$ [NC] 
#RewriteCond %{HTTP_HOST} !^(.+)\.my-example\.net$ [NC] 
#RewriteRule ^(.*)$ http://example.com/$1 [L,QSA,R=301] 

#RewriteCond %{HTTP_HOST} !^www 
#RewriteRule .? http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
#RewriteCond %{REQUEST_URI} ^(application|system) 
#RewriteRule .? index.php?/%{REQUEST_URI} [L] 
#RewriteCond %{REQUEST_FILENAME} !-f 
#RewriteCond %{REQUEST_FILENAME} !-d 
#RewriteRule .? index.php?/%{REQUEST_URI} [L] 

#RewriteCond %{HTTP_HOST} ^www\.my-example\.net$ 
#RewriteCond %{HTTP_HOST} ^www\.my-example\.net$ [OR] 
#RewriteCond %{HTTP_HOST} ^my-example\.net$ 
#RewriteRule^http://example.com%{REQUEST_URI} [R=301,L,NE] 
# Extract the subdomain part of domain.com 
#RewriteCond %{HTTP_HOST} ^((?!www)[^.]+)\.my-example\.net$ [NC] 
# Check that the subdomain part is not www, dev, old, or new 
#RewriteCond %1 !^(www|dev|old|new)$ [NC] 
# Redirect all requests to the original url /blog 
#RewriteRule ^.*$ /%1 [L] 

答えて

0

ServerName my-example.netが記載されているVirtualHost句内で、example.comにリダイレクトを設定します。

ServerName www.my-example.netが記述されているVirtualHost句の中で、同様に設定します。

「その他すべてのサブドメイン」部分には、DNS Aレコード(「*」ワイルドカードなど)とApacheの設定の両方が含まれます。まず、またはpingを使用して、サブドメイン "foo"がWebサーバーのA(またはAAAA)レコードを生成するかどうか、つまりApacheが決定を下すかどうかを確認します。次に、fooにVirtualHost句を追加するか、Apacheのワイルドカードデフォルトマッチングに頼って、必要に応じて200または302または404のドキュメントを提供します。

DNSは、クライアントのGET要求がポート80/443に到着するかどうかを制御します。クライアントは要求に「Host:foo.my-example.net」ヘッダーを送信します。 ApacheのVirtualHost引数はstrcmp()に渡され、クライアントの「Host:」ヘッダーと比較されます。その比較の結果は、残りのVirtualHost句がこの要求に使用されるかどうかを制御します。

関連する問題