Howdy, Stranger!

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

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

Categories

In this Discussion

Who's Online 8

GumCloudMarc905ericgillette +5 guests

Dynamic subdomains for profiles

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.






Comments

  • Posts: 2,058
    <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]

Sign In or Register to comment.