Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Subdomains for redirection only

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 redirect 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.

like image 749
Adam Strudwick Avatar asked Feb 21 '26 12:02

Adam Strudwick


1 Answers

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.

like image 185
markus Avatar answered Feb 23 '26 09:02

markus