1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Put Vbulletin Blog/cms On It's Own Sub-domain

Discussion in 'vBulletin' started by digitalpoint, Apr 14, 2010.

  1. #1
    Putting secondary vBulletin products on their own sub-domain (like we do here) turned out to be much simpler than I anticipated. Of course, I say that now after I spent countless hours working on methods that ultimately didn't work in the end for one reason or another. :)

    For this method, you need to be running the Apache web server and have the ability to define mod_rewrite rules for it.

    My example is specifically for vBulletin blogs, but the same idea could be applied to any vBulletin module (like CMS).

    Create Blog Directory
    Create a directory called blogs within your normal vBulletin installation directory (this should be at the same level where all the normal blog*.php files are at).

    Create PHP files named the same as the normal PHP files that just include the actual ones.

    These files really are nothing more than pointer files to tell Apache where the actual file is (this method is simpler than trying to create a ton of mod_rewrite rules to handle all the blog files.

    Configure Apache
    These are the rewrite rules I use for this site (keep in mind that the ServerAlias directive will only work in the Apache config file for your site, and will not work in an .htaccess file; also make sure your DNS is resolving the new sub-domain properly):
    ServerAlias blogs.yourdomain.com
     
    RewriteCond %{HTTP_HOST}        ^blogs.*
    RewriteCond %{REQUEST_URI}      !^\/blogs\/.*
    RewriteRule ^(.*)$              /blogs/$1 [L]
     
    RewriteCond %{HTTP_HOST}        !^blogs.*
    RewriteCond %{REQUEST_URI}      ^\/blog [OR]
    RewriteCond %{REQUEST_URI}      ^\/entry\.php
    RewriteRule ^(.*)$              http://blogs.yourdomain.com$1 [R=301,L]
    Code (apache):
    This will handle passing through a request to the blogs.yourdomain.com host to the proper blogs directory. It will also handle the redirection of old URLs to the new URL.

    Create Plugin
    Create a plugin at the global_complete location with the following line of code:
    $output = preg_replace(array ('#(href|action)="blog.php#i', '#(href|action)="(blog_ajax|blog_attachment|blog_callback|blog_external|blog_inlinemod|blog_post|blog_report|blog_search|blog_subscription|blog_tag|blog_usercp|entry).php#i'), array('\1="http://blogs.yourdomain.com/', '\1="http://blogs.yourdomain.com/\2.php'), $output);
    PHP:
    All this does is alter the existing relative URLs to be absolute URLs.

    Maybe someday vBulletin will have a Blog URL option to make this step not necessary.

    Edit Blog JavaScript Files
    Hopefully vBulletin will address this bug soon. If they do, this step will no longer be necessary.

    In order to have the AJAX functions work, we need to edit the blog JavaScript files (these are the clientscript/blog* files).

    blog_ajax_calendar.js
    Change this:
    asyncRequest("POST","blog_ajax.php
    Code (javascript):
    to this:
    asyncRequest("POST",window.location.protocol+"//"+window.location.hostname+"/blog_ajax.php
    Code (javascript):
    blog_ajax_latest.js
    Change this:
    asyncRequest("POST","blog_ajax.php
    Code (javascript):
    to this:
    asyncRequest("POST",window.location.protocol+"//"+window.location.hostname+"/blog_ajax.php
    Code (javascript):
    blog_ajax_rate.js
    Change this:
    asyncRequest("POST","blog.php
    Code (javascript):
    to this:
    asyncRequest("POST",window.location.protocol+"//"+window.location.hostname+"/blog.php
    Code (javascript):
    blog_ajax_tagsugg.js
    Change this:
    asyncRequest("POST","blog_tag.php
    Code (javascript):
    to this:
    asyncRequest("POST",window.location.protocol+"//"+window.location.hostname+"/blog_tag.php
    Code (javascript):
    blog_dragdrop.js
    Change this:
    asyncRequest("POST","blog_ajax.php
    Code (javascript):
    to this:
    asyncRequest("POST",window.location.protocol+"//"+window.location.hostname+"/blog_ajax.php
    Code (javascript):
    blog_quick_edit.js
    Change this (in two locations):
    asyncRequest("POST",this.factory.ajaxtarget
    Code (javascript):
    to this:
    asyncRequest("POST",window.location.protocol+"//"+window.location.hostname+"/"+this.factory.ajaxtarget
    Code (javascript):
    blog_quick_load.js
    asyncRequest("POST",this.factory.ajaxtarget
    Code (javascript):
    to this:
    asyncRequest("POST",window.location.protocol+"//"+window.location.hostname+"/"+this.factory.ajaxtarget
    Code (javascript):
     
    Last edited: Jan 26, 2013
    digitalpoint, Apr 14, 2010 IP
  2. Brandon Sheley

    Brandon Sheley Illustrious Member

    Messages:
    9,721
    Likes Received:
    612
    Best Answers:
    2
    Trophy Points:
    420
    #2
    Loco.M, you do not have permission to access this page. This could be due to one of several reasons:
     
    Brandon Sheley, Apr 15, 2010 IP
  3. HJITechnologiesLLC

    HJITechnologiesLLC Well-Known Member

    Messages:
    466
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    145
    #3
    Awesome Job. :)
     
    HJITechnologiesLLC, Apr 16, 2010 IP
  4. Ruddo

    Ruddo Member

    Messages:
    821
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    43
    #4
    Thanks for sharing the creation process
     
    Ruddo, Apr 16, 2010 IP
  5. ractors

    ractors Well-Known Member

    Messages:
    1,979
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    140
    #5
    wow nice info

    thx
     
    ractors, Apr 17, 2010 IP
  6. ractors

    ractors Well-Known Member

    Messages:
    1,979
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    140
    #6
    ractors, Apr 25, 2010 IP
  7. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,333
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #7
    Check your server logs. Do you maybe not have it setup to allow mod_rewrite rules?

    Make sure they are in the virtual site config file for Apache (the ServerAlias directive can't go in a .htaccess file if that's what you are trying to do).
     
    digitalpoint, Apr 25, 2010 IP
  8. anthony parsons

    anthony parsons Well-Known Member

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    111
    #8
    Hey Shaun,

    Quick question... is the below correct if I wanted to change it from blogs.domain.com to news.domain.com?

    ServerAlias news.yourdomain.com

    RewriteCond %{HTTP_HOST} ^news.*
    RewriteCond %{REQUEST_URI} !^\/blogs\/.*
    RewriteRule ^(.*)$ /blogs/$1 [L]

    RewriteCond %{HTTP_HOST} !^news.*
    RewriteCond %{REQUEST_URI} ^\/blog [OR]
    RewriteCond %{REQUEST_URI} ^\/entry\.php
    RewriteRule ^(.*)$ http://news.yourdomain.com$1 [R=301,L]
     
    anthony parsons, Apr 26, 2010 IP
  9. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,333
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #9
    Yep... just by looking at it (without actually trying it on a live server), it seems it should work.
     
    digitalpoint, Apr 26, 2010 IP
  10. ChipTz

    ChipTz Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    hello,

    Is the last step also required for vb 4.0.4 PL1?
     
    ChipTz, Jun 27, 2010 IP
  11. ChipTz

    ChipTz Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Hi,

    can't manage to get this to work, what has to be done regarding DNS?

    I think this is where I get it wrong:

    also make sure your DNS is resolving the new sub-domain properly)
     
    ChipTz, Jun 27, 2010 IP
  12. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,333
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #12
    All steps are required.

    You need to set up the sub-domain in your DNS just like your main site URL. For example forums.digitalpoint.com, tools.digitalpoint.com, articles.digitalpoint.com, blogs.digitalpoint.com, etc. all resolve to 216.9.35.60
     
    digitalpoint, Jun 28, 2010 IP
  13. tescorg

    tescorg Member

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #13
    How did you stop the CMS from redirecting root (/) to content url (/content/1-the-front-page as example)?

    I want "site.com" to open up the first section, content id 1, but it always redirects to "site.com/content/1-the-front-page".
     
    tescorg, Aug 1, 2010 IP
  14. Animemike

    Animemike Greenhorn

    Messages:
    69
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #14
    lol am stuck on

    "Configure Apache
    These are the rewrite rules I use for this site (keep in mind that the ServerAlias directive will only work in the Apache config file for your site, and will not work in an .htaccess file; also make sure your DNS is resolving the new sub-domain properly):" Where is this file normaly :S

    Edit i found the file no idea where to add this tho :/
     
    Last edited: Aug 7, 2010
    Animemike, Aug 7, 2010 IP
  15. Animemike

    Animemike Greenhorn

    Messages:
    69
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #15
    Ok now i just get a "vBulletin Message" saying my forums title and it logs me out on blogs. :X
     
    Animemike, Aug 7, 2010 IP
  16. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,333
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #16
    Hmmm... I didn't do anything special here. What settings do you have under AdminCP -> Settings -> Options -> Content Management ? Specifically, I would double check the CMS URL and Default Page.


    It can be anywhere within the <VirtualHost> container in the .conf file. For example, this is how the first few lines look for this site:
    <VirtualHost *:80>
    	ServerAdmin admin@digitalpoint.com
    	ServerName forums.digitalpoint.com
    	ServerAlias articles.digitalpoint.com blogs.digitalpoint.com directory.digitalpoint.com marketplace.digitalpoint.com tools.digitalpoint.com
    Code (markup):
    Strange... do you have a URL I can see it at?

    If you are getting logged out when you view sub-domains, you might need to check your cookie settings to work for all sub-domains, vs. just the specific one you logged in to. In your normal vB options, check the Cookie Domain setting. It should be set to ".yourdomain.com" from the drop-down list.

    One thing you need to be aware of though is when you expand cookies to work on sub-domains, vBulletin does NOT remove the old sub-domain specific cookies when you log out. This can cause problems after people change their password if they were previously setup to stay logged in. For this site, I manually hacked the login.php file to remove ALL cookies (even the old ones) when someone hits the Logout button. That way if someone is having issues with staying logged in, you can just have them manually hit the Logout button and relogin and then they can properly stay loged in. It's a bit of a pain in the ass, but there's not a way to globally change user's existing cookies that were already set with the old setting.

    For my login.php, after the define('NOPMPOPUP', true); line, I added this:
    // Remove sub-domain specific cookies 
    foreach ($_COOKIE as $key => $val) {
    	if (substr($key, 0, 2) != '__') setcookie($key, '', $time - 3600);
    }
    PHP:
    This will remove ALL cookies on logout EXCEPT Google Analytic ones (they start with __).
     
    digitalpoint, Aug 7, 2010 IP
  17. Animemike

    Animemike Greenhorn

    Messages:
    69
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #17
    Yes hehe i just did that
    before i saw this post

    All is working now cms next :) thanks alot Shaun
     
    Animemike, Aug 7, 2010 IP
  18. Deathjam

    Deathjam Well-Known Member

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    151
    #18
    thx for this, i now have the blogs working on a subdomain, using the blogs as an example i also have the cms on a subdomain, as far as i can see, everything on the cms works except for the configure widgets in the admincp, the overlay attemps to pop up, but then goes away again.

    Would it be possible for you to give a quick run through of whats needed for the cms to work, in-case i missed anything.

    Thanks
     
    Deathjam, Aug 16, 2010 IP
  19. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,333
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #19
    There really shouldn't be anything that needs to change in the admincp as far as I know. The admincp isn't on a different sub-domain, is it?
     
    digitalpoint, Aug 20, 2010 IP
  20. Deathjam

    Deathjam Well-Known Member

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    151
    #20
    its all installed to forums.domain.com

    so its forums.domain.com/admincp

    the cms is on articles.domain.com

    if i copy the configure link its

    hxxp://forums.domain.com/admincp/cms_admin.php?do=widget

    but firebug show the link as


    <a onclick="return cms_show_overlay('hxxp://articles.domain.com/widget.php?config/8' )" href="">Configure</a>
    HTML:
     
    Deathjam, Aug 20, 2010 IP