Mobile app version of vmapp.org
Login or Join
Miguel251

: Mod_rewrite rule for wildcard subdomains? Sorry if this has been covered, I can't find anything on this specifically. I have wildcard subdomains on (*.mysite.com) I need a mod_rewrite expression

@Miguel251

Posted in: #ModRewrite

Sorry if this has been covered, I can't find anything on this specifically.

I have wildcard subdomains on (*.mysite.com) I need a mod_rewrite expression for this rewrite:

bob.mysite.com => mysite.com/users/index.php?user=bob

bob.mysite.com/profile/ => mysite.com/users/index.php?user=bob/profile/

Obviously "bob" and "profile" are just examples, I need the general case. Thanks for your help!

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Miguel251

1 Comments

Sorted by latest first Latest Oldest Best

 

@Becky754

The $ operator will let you extract backreferences from matches in rewrite rules and the % operator will let you extract references from conditions.

RewriteCond %{HTTP_HOST} !www.mysite.com$ [NC] # Presuming you don't want to do www
RewriteCond %{HTTP_HOST} ^(.*).mysite.com [NC] # Catch subdomain
RewriteCond %{REQUEST_URI} !index.php [NC] # Don't rewrite if we already have
RewriteRule ^(.*)$ /users/index.php?user=%1 [L]

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme