问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/54011867/how-to-make-a-tumblr-style-profile-url