How to make a tumblr style profile url

大兔子大兔子 提交于 2020-01-23 07:20:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!