5

I wonder, how does tumblr doing profile url like this:

http://www.username.tumblr.com/ 
http://username.tumblr.com/

I know we can change the profile url

http://www.website.com/profile.php?user=username

to

http://www.website.com/username

using the following RewriteRule

RewriteRule ^([^/]+)/?$ profile.php?user=$1 [L,QSA,NC]

I don't know how tumblr doing those profile urls.

How can we make user profile urls like this:

http://www.username.website.com/
http://username.website.com/

I have a VirtualHost.

Justin Iurman
  • 18,954
  • 3
  • 35
  • 54
AlwaysStudent
  • 1,354
  • 18
  • 49
  • 1
    Duplicate: https://stackoverflow.com/questions/183928/how-to-let-php-to-create-subdomain-automatically-for-each-user – Quentin Jan 07 '19 at 15:25
  • 1
    Another duplicate: https://stackoverflow.com/questions/6840724/subdomain-for-each-user – Quentin Jan 07 '19 at 15:26
  • Yet another duplicate: https://stackoverflow.com/questions/12408582/virtual-subdomain-one-subdomain-per-user – Quentin Jan 07 '19 at 15:26
  • Still more duplication: https://stackoverflow.com/questions/4116898/how-do-i-create-personal-sub-domain-programmatically-with-php – Quentin Jan 07 '19 at 15:26
  • And more: https://stackoverflow.com/questions/1841006/create-subdomain-upon-user-registration – Quentin Jan 07 '19 at 15:26

1 Answers1

7

Key solution: wildcard subdomains.

This allows you to make *.domain.com point to your server.

From your example, let's say we enabled wildcard subdomains for domain.com and we want to provide user subdomains, such as http://username.domain.com. You'd have something like this:

RewriteCond %{HTTP_HOST} ^((?!www.)[^.]+)\.domain\.com$ [NC]
RewriteRule ^(.*)$ /%1/$1 [L]

where http://username.domain.com/xxx would point to /username/xxx.

Note that this example has been reduced and simplified as much as possible for the explanation. You'd maybe need other rules, depending on your context, to handle main domain and other conditions.

Justin Iurman
  • 18,954
  • 3
  • 35
  • 54