2010-02-23 44 views

回答

3

您需要使用括号抢值匹配,你的情况:

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

假设你也想重定向到http://[random-string].domain.com/somethinghttp://domain.com/folder/[random-string]/something

+0

嗯,$ 1变量仍然缺少。 (它重定向到http://domain.com/folder//) – Yongho 2010-02-26 15:15:13

+0

好吧,我的错误,请参阅编辑我的回答(RewrtieCond使用%而不是$) – gregseth 2010-02-26 20:21:22

+0

干杯!对我来说工作得很好,1美元是奖金。 – 472084 2012-07-04 09:26:42

0

如何解决呢? 我的子域不是随机的 有哪里可以替换$ 1? 欢呼声

的RewriteCond%{HTTP_HOST} ^(。).domain.com 重写规则^(。)$ http://domain.com/folder/%1/ $ 1 [R = 301,L]