Reputation: 327
I need help in writing a mod_rewrite to allocate users their own personal subdomains.
I want to convert sub.domain.com to sub.domain.com/profile?user=sub
but if user opens any page the 'user' variable should also be passed i.e.
sub.domain.com/page to sub.domain.com/page?user=sub
It should be masked i.e. no redirect
Upvotes: 0
Views: 196
Reputation: 143946
Try adding this to the htaccess file in your document root
# 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]
Upvotes: 1