2011-01-28 10 views
1

私は次のように適用されるので、変数に未知のサブドメインを変換するために必要ています:モッズ書き換え - 高度な問題

  • http://test.example.com/http://www.example.com/?domain=test

  • http://xyz.example.com/http://www.example.com/?domain=xyz

  • http://www.example.com/http://www.example.com/

  • http://www.example.com/pageA/http://www.example.com/pageA/

  • http://fish.example.com/pageB?somevar=somethinghttp://www.example.com/pageB?somevar=something&domain=fish

  • http://www.example.com/pageB?somevar=somethinghttp://www.example.com/pageB?somevar=something

  • http://fish.example.com/pageBhttp://www.example.com/pageB?domain=fish

あなたは私がする必要があるすべてを見ることができるようにして任意のサブドメインを置き換えるですwwwとし、サブドメイン名をドメインと呼ばれるget varとして追加します。

私は本当にこれで失われています。

編集:ああ、ユーザーには、リダイレクトするのではなく、URLのサブドメインが表示されるようにしたいと考えています。これはまた、...?domain=fishwww.fish.example.comを書き換えます

RewriteEngine on 
RewriteCond %{HTTP_HOST} !=www.example.com 
RewriteCond %{HTTP_HOST} ^(www\.|)(.+)\.example\.com$ 
RewriteRule ^.*$ http://www.example.com/$1?domain=%2 [QSA] 

:私が使用する

RewriteEngine on 
RewriteCond %{HTTP_HOST} ^([a-z]+)\.example\.com$ 
RewriteCond %1 !=www 
RewriteRule^http://www.example.com%{REQUEST_URI}?domain=%1 [QSA] 

答えて

1

はこれを試してみてください。

+0

これは他のget varsを保持しますか?例えば?var = test&domain = xx – DwayneBull

+0

@DwayneBull:はい、* QSA *フラグは自動的に元の要求されたクエリを新しいものに追加します。 – Gumbo

+0

私は[P、QSA]を追加し、最初の行をRewriteCond%{HTTP_HOST}に変更しました!^ www \ .example \ .com $それで完璧に働きました。ありがとう。 – DwayneBull