Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

Categories as subdomains

edited July 2011 in Vanilla 2.0 - 2.8
Anyone have an idea of how to use subdomains for the different categories?
Such as:
example.com/categories/general/ to
general.example.com

It seems it's not straightforward to do, since there is no actual directories named "categories" or "general".

Thanks for the help.

Best Answer

  • Options
    LincLinc Detroit Admin
    edited July 2011 Answer ✓
    This is a complex task that I think is a bit beyond what I'd expect to be explained on a message board. This will minimally require knowledge of Apache virtual hosts and probably mod_rewrite and advanced Vanilla work. My initial reaction (having a good deal of experience in adventures like this) is "this is far more trouble than it is worth."

Answers

  • Options
    LincLinc Detroit Admin
    edited July 2011 Answer ✓
    This is a complex task that I think is a bit beyond what I'd expect to be explained on a message board. This will minimally require knowledge of Apache virtual hosts and probably mod_rewrite and advanced Vanilla work. My initial reaction (having a good deal of experience in adventures like this) is "this is far more trouble than it is worth."
  • Options
    SS ✭✭
    1) First of all, you need configure DNS: * IN A x.x.x.x or * IN CNAME myhost.com
    2) Configure apache thus that it will accept all requests for IP-address (not virtual, but the real host)
    3) In PHP you can parse $_SERVER['HTTP_HOST'] and get requested subdomain.
    4) Redispatch event with new REQUEST_URI (faked), 'BeforeDispatch' is good place for it.
    Example (plugin function, or application hooks):

    public function Gdn_Dispatcher_BeforeDispatch_Handler($Sender) {
    $Request = Gdn::Request();
    $RequestHost = $Request->Host();
    $IsIpHost = (is_int(ip2long($RequestHost)));
    if (C('Garden.Domain') != $Request->Domain() && $IsIpHost === False) {
    $this->IsSubdomainRequest = True;
    $URI = $Request->RequestUri();
    if (substr($RequestHost, 0, 4) == 'www.') $RequestHost = substr($RequestHost, 4);
    $UrlCode = GetValue(0, explode('.', $RequestHost));
    $CategoryModel = new CategoryModel();
    $Category = $CategoryModel->GetByCode($UrlCode);
    if (!$Category) throw NotFoundException();

    if ($URI == '') { // only for empty uri
    $Request->WithControllerMethod('categories', Null, array($Category->CategoryID));
    } else {
    $this->bCheckInAfterAnalyzeRequest = True;
    // We have dynamic domain, so do redirect to home if knowingly bad subdomain requested
    // See Gdn_Dispatcher_AfterAnalyzeRequest_Handler()
    Redirect(DomainUrl(), 301);
    }
    }
    }


  • Options
    I would love to have this functionality as well. @ImWithStupid, did you find a solution?
Sign In or Register to comment.