Dynamic subdomains for profiles
  • SS
    Posts: 454
    Task: Dynamic subdomains for profile pages (or any other similar /xxx/yyy/zzz)
    http://vanillaforums.org/profile/mark =>
    http://mark.vanillaforums.org/
    Also: Apache, mod_rewrite, configured DNS (any request to *.site.com points to the same IP as site.com).

    Problems:
    1. Cannot think mod_rewrite rule.
    2. Canonical URL: mark.vanillaforums.org/profile/mark <--- incorrect! correct is vanillaforums.org/profile/mark<br />Possible issue 479 is related to this problem

    Question: no question, just wonder to discuss.






  • LincolnLincoln
    Posts: 2,016
    <VirtualHost *:80>
    ServerName yoursite.com
    DocumentRoot /path/to/docroot
    ErrorLog /path/to/logs/yoursite
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^yoursite\.com$ [NC] # Has subdomain
    RewriteCond %{HTTP_HOST} !^www\.yoursite\.com$ [NC] # Not www
    RewriteRule ^(.*)\.yoursite\.com$ /profile/$1 [PT,L] # Silent redirect
    RewriteCond %{HTTP_HOST} !^yoursite\.com$ [NC] # Has subdomain
    RewriteCond %{HTTP_HOST} !^www\.yoursite\.com$ [NC] # Not www
    RewriteRule ^(.*)\.yoursite\.com(.*) yoursite\.com/$2 [L] # Redirect if not profile
    </VirtualHost>

    Untested! Just my Monday-morning conjecture :)

    Vanilla developer [GitHub, Twitter]

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Login with Facebook Sign In with Google Sign In with OpenID Sign In with Twitter

In this Discussion

Who's Online 1

paintballer82