mod_rewrite用于通配符子域

时间:2012-07-21 19:54:15

标签: apache mod-rewrite

我需要帮助编写mod_rewrite来为用户分配他们自己的个人子域。

我想将sub.domain.com转换为sub.domain.com/profile?user=sub

但如果用户打开任何页面,也应传递'user'变量,即

sub.domain.com/page到sub.domain.com/page?user=sub

它应该被屏蔽,即没有重定向

1 个答案:

答案 0 :(得分:1)

尝试将其添加到文档根目录

中的htaccess文件中
# for / requests
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com$ [NC]
# this step may not be necessary if you don't care about "www.domain.conm"
RewriteCond %1 !www
RewriteRule ^$ /profile?user=%1 [QSA,L]

# for any "page"
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com$ [NC]
# this step may not be necessary if you don't care about "www.domain.conm"
RewriteCond %1 !www
RewriteRule ^(.*)$ /$1?user=%1 [QSA,L]