开发者

Subdomains for redirection only

开发者 https://www.devze.com 2023-04-04 08:17 出处:网络
My domain is meeting.com. I work with PHP, jQuery, for the main part. No ASP. When a user creates an account, I\'d like a subdomain user.meeting.com to be created for REDIRECTION purposes only. I do

My domain is meeting.com.

I work with PHP, jQuery, for the main part. No ASP.

When a user creates an account, I'd like a subdomain user.meeting.com to be created for REDIRECTION purposes only. I don't want the subdomain to exist for real.

When someone would load john13.meeting.com, I would like the website to redirec开发者_如何学编程t to meeting.com?user=john13 (I don't care if john13.meeting.com remains in the URL bar).

What is the most efficient and easy method of doing it automatically in PHP or Apache? Please consider performance too since I have many users.


You don't need PHP for that. The right Apache configuration with the rewrite module on, will do the trick.

For example (not tested):

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

Or if you're not rewriting further for SEO, the rule could be

RewriteRule ^$ /index.php?user=%1 [L]

For more inspiration, check out the link Shef posted with another example of how to achieve this.

0

精彩评论

暂无评论...
验证码 换一张
取 消