【发布时间】:2012-10-13 12:51:07
【问题描述】:
我现在在网上搜索了几天,但没有找到任何答案。这就是我想做的:
我网站上的每个用户都会收到一个个人子域,例如http://username.domain.com。 当然这是一个虚拟子域。
现在,我已经设置了通配符 DNS A 记录,打开 mod_rewrite 并实现:
当有人浏览 http://anysubdomain.domain.com 时,他们会被重定向到 http://www.domain.com/sub/index.php?var=anysubdomain。在 index.php 中有一个函数可以根据 'var' 变量(子域的名称)获取唯一信息。
我想要做的是当有人浏览 http://anysubdomain.domain.com 他被重定向到 http://www.domain.com/sub/index.php?var=anysubdomain (就像现在) 但原始 URL (http://anysubdomain.domain.com) 保留在浏览器栏中。所以看起来每个用户都有自己的子域。
这是我目前使用的htaccess文件:
RewriteEngine On
Options +FollowSymlinks
RewriteCond %{HTTP_HOST} !^www\.domain\.com
RewriteCond %{HTTP_HOST} !^static\.domain\.com
RewriteCond %{HTTP_HOST} ^(www\.)?(.+)\.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/sub/index.php?username=%2 [L]
我希望一切都清楚,如果没有:询问,我提供更多信息!
提前致谢!
尤里
【问题讨论】:
标签: .htaccess redirect subdomain