2013-10-17 44 views
0

我有一个域,www.example.com和子域test.example.com。当我打电话test.example.com时,我需要将其重定向到www.example.com/search/property/test_state,而不更改test.example.com的网址。所以url应该看起来像test.example.com。.htaccess从子域名的文章重定向到主域名无子域URL更改

我这样做是用的.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主域。 当前当我访问它时,它将重定向到主域。有任何想法吗?

回答

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] 
+0

不工作..我需要两个重定向。其中一个应该将test.example.com重定向到http://www.example.com/search/property/test_state,第二个则是将test.example.com/any_urls.php重定向到http://www.example.com/。 any_urls.php但是浏览器应该在两种情况下都显示子域url。在第二种情况下,它显示邮件域的网址。 –

+0

@ user2890708在第一种情况下(相同的文档根目录),更改很简单。在不同文档根的情况下,需要额外的代理规则 –