Anything.DomainName.com使用.htaccess重定向到DomainName.com/xx/test.html

时间:2011-04-16 10:20:24

标签: apache .htaccess mod-rewrite

我想使用.htaccess将WildChar.DomainName.com重定向到DomainName.com/xx/test.html

.htaccess代码是

Options +FollowSymLinks

<IfModule mod_rewrite.c>

RewriteEngine on

RewriteCond %{HTTP_HOST} ^\.DomainName\.com
RewriteRule ^(.*)$ /xx/index.html [L]

</IfModule>

[更新]我因某些原因无法发布到superuser.com,所以请不要关闭/移动此问题

由于 让

1 个答案:

答案 0 :(得分:0)

你可以尝试这个:

RewriteCond %{HTTP_HOST} ^(.+)\.domainname\.com
RewriteRule .* http://domainname.com/xx/index.html [R]

条件应匹配任何非空子域。

如果要将有关访问哪个子域的信息传递给重定向的站点,则可以将%1(这是RewriteCond中的第一个正则表达式匹配)添加到重定向,例如

RewriteRule .* http://domainname.com/xx/index.html?from_subdomain=%1 [R]