0

ドメイン www.example.com とサブドメイン test.example.com があります。test.example.com を呼び出すとき、test.example.com の URL を変更せずに、これを www.example.com/search/property/test_state にリダイレクトする必要があります。したがって、URL は test.example.com のみのようになります。

私は .htaccess コードでこれを行いました。

RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} !^webmail\.example\.com
RewriteCond %{HTTP_HOST} !^m\.example\.com
RewriteCond %{HTTP_HOST} ([^.]+)\.example\.com
RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteRule  ^$ /search/property/%1_state [P]

この後、test.example.com/content/sell_your_home のようなサブドメインから URL にアクセスすると、URL がメイン ドメインに変更されません。現在、これにアクセスすると、メイン ドメインにリダイレクトされます。何か案は?

4

1 に答える 1

0

テスト サブドメインにメイン ドメインと同じサーバー ルート (ドキュメント ルート) がある場合、Pフラグは必要ありません。

RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} !^webmail\.example\.com
RewriteCond %{HTTP_HOST} !^m\.example\.com
RewriteCond %{HTTP_HOST} ([^.]+)\.example\.com
RewriteRule  ^$ /search/property/%1_state/ [L]

それ以外の場合は、完全な URL が必要です。

RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} !^webmail\.example\.com
RewriteCond %{HTTP_HOST} !^m\.example\.com
RewriteCond %{HTTP_HOST} ([^.]+)\.example\.com
RewriteRule  ^$ http://www.example.com/search/property/%1_state/$1 [L,P]

RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} !^webmail\.example\.com
RewriteCond %{HTTP_HOST} !^m\.example\.com
RewriteCond %{HTTP_HOST} ([^.]+)\.example\.com
RewriteRule  ^(.*)$ http://www.example.com/$1 [L,P]
于 2013-10-17T13:57:25.063 に答える