I keep all my different sites domains organized in public_html like so:
public_html/site1.com
public_html/sub.site1.com
public_html/site2.com
public_html/site3.com
public_html/sub.mainsite.com
public_html/mainsite.com
When doing domain add-ons and subdomains via cPanel I can easily point each domain or subdomain to the appropriate folder. The only exception is the main domain associated with my server (mainsite.com) which, since it's not an add-on domain, won't let me easily set the appropriate path.
I found this similar thread:
http://forums.asmall...h__1#entry81674
Since i'm on a VPS, I was able to make the change myself in httpd.conf....
<VirtualHost 129.121.182.131:80>
ServerName mainsite.com
ServerAlias www.mainsite.com
DocumentRoot /home/user_name/public_html/mainsite.com
ServerAdmin mainsite@mainsite.com
[...etc...]
</VirtualHost>
It works as expected, but my question is more about best practices. Is there a better way to do this? Do I run the risk of my changes getting overridden since I edited httpd.conf directly?
When I attempted to do it via WHM: Include Editor: Post VirtualHost Include it didn't work.
Best method of changing the document root of your primary domain
Started by
susanbuck
, Jun 20 2012 08:20 PM
2 replies to this topic
#1
Posted 20 June 2012 - 08:20 PM
#2
Posted 10 July 2012 - 02:43 AM
Hi Susan,
There is a better way of changing DocumentRoot for main domain, by editing userdata file for each domain. You have to edit this file:
/var/cpanel/userdata/USERNAME/DOMAIN.COM (replace USERNAME and DOMAIN.COM with actual info).
In that file, find these two lines:
documentroot: /home/USERNAME/public_html
path: /home/USERNAME/public_html/cgi-bin
And, edit them accordingly:
documentroot: /home/USERNAME/public_html/SUBDIR
path: /home/USERNAME/public_html/SUBDIR/cgi-bin
Save file, and then delete cache file for that domain:
rm -fv /var/cpanel/userdata/USERNAME/DOMAIN.COM.cache
If domain has SSL certificate installed, you would have to do the same for:
/var/cpanel/userdata/USERNAME/DOMAIN.COM_SSL
And, delete:
/var/cpanel/userdata/USERNAME/DOMAIN.COM_SSL.cache
Run these two scripts:
/scripts/updateuserdatacache
/scripts/rebuildhttpdconf
Restart Apache, and that should do it.
Although this will work for that domain, it's not an ideal solution, since that change won't live through account migration. If you'll ever migrate that account to some other server, DocumentRoot for main domain will reset back to public_html.
Other solution would be to just set up a redirection rule that would redirect all requests on that domain to subdirectory of your choice. If you add that redirection through cPanel, it will also rewrite Address Bar in your browser to that subdirectory. If you want to avoid that, you can add it manually in .htaccess:
Add that to /home/USERNAME/public_html/.htaccess
If you'll need any additional assistance, please feel free to open a ticket with our Support team, and we'll be happy to assist you.
There is a better way of changing DocumentRoot for main domain, by editing userdata file for each domain. You have to edit this file:
/var/cpanel/userdata/USERNAME/DOMAIN.COM (replace USERNAME and DOMAIN.COM with actual info).
In that file, find these two lines:
documentroot: /home/USERNAME/public_html
path: /home/USERNAME/public_html/cgi-bin
And, edit them accordingly:
documentroot: /home/USERNAME/public_html/SUBDIR
path: /home/USERNAME/public_html/SUBDIR/cgi-bin
Save file, and then delete cache file for that domain:
rm -fv /var/cpanel/userdata/USERNAME/DOMAIN.COM.cache
If domain has SSL certificate installed, you would have to do the same for:
/var/cpanel/userdata/USERNAME/DOMAIN.COM_SSL
And, delete:
/var/cpanel/userdata/USERNAME/DOMAIN.COM_SSL.cache
Run these two scripts:
/scripts/updateuserdatacache
/scripts/rebuildhttpdconf
Restart Apache, and that should do it.
Although this will work for that domain, it's not an ideal solution, since that change won't live through account migration. If you'll ever migrate that account to some other server, DocumentRoot for main domain will reset back to public_html.
Other solution would be to just set up a redirection rule that would redirect all requests on that domain to subdirectory of your choice. If you add that redirection through cPanel, it will also rewrite Address Bar in your browser to that subdirectory. If you want to avoid that, you can add it manually in .htaccess:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} domain.com
RewriteCond %{REQUEST_URI} !subdirectory/
RewriteRule ^(.*)$ subdirectory/$1 [L]
Add that to /home/USERNAME/public_html/.htaccess
If you'll need any additional assistance, please feel free to open a ticket with our Support team, and we'll be happy to assist you.
Tomica Hleb
Customer Support Supervisor
A Small Orange LLC
http://www.asmallorange.com
Customer Support Supervisor
A Small Orange LLC
http://www.asmallorange.com
#3
Posted 11 January 2013 - 04:30 AM
The .htaccess method so far works for me. Here's an update for it to also support subdomains:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain.com
RewriteCond %{REQUEST_URI} !subdirectory/
RewriteRule ^(.*)$ subdirectory/$1 [L]
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users
Sign In
Create Account








