enigmas

Registered
Jul 2, 2010
3
0
51
Hello,

I face the following issue, I have a hosted domain and my default root site directory is /public_html/ the problem is that I register several domains, with the site addon option from cpanel, which all of them have the root site directory in public_html, I want to change the site root directory of the primary domain to something like /public_html/primary, in this way all of my domains will have his own directory in /public_html.

I've managed to trick the apache server with a .htaccess rule to rewrite the url from www.primary.co/primary to www.primary.co, at this moment I've faced another issue with the cgi-bin engine, I've solved that also with +execCGI rule on the .htaccess, but now the cgi binary (cgiemail) is tricked by my rewrite rule and doesn't know to get his template file.

Does any one have a solution to change the default /public_html root site or how do i instruct the cgiemail to get the right path?

.htaccess in /public_html/
Code:
RewriteEngine on
RewriteCond %{HTTP_HOST} primary.co
RewriteCond %{REQUEST_URI} !^/primary
RewriteRule ^(.*)$ primary/$1 [L]
.htaccess in /public_html/primary/cgi-bin/
Code:
Options +ExecCGI
SetHandler cgi-script
In conclusion my /public_html/ should contain the following directories:
primary (main domain)
secondary1 (addon domain1)
secondary2 (addon domain2)
secondaryn (addon domainn)

Regards,

Solved the issue, wrong sintax of the cgiemail:

wrong:
Code:
cgi-bin/cgiemail/template
good:
Code:
cgi-bin/cgiemail/primary/template
Hope this info will help someone.
 
Last edited:

madaboutlinux

Well-Known Member
Jan 24, 2005
1,051
2
168
Earth
Not sure about the Google indexes but to change the DocumentRoot of a domain, you need to edit the Apache configuration file and edit the value of "DocumentRoot" parameter in the domains VirtualHost entry. Edit the apache configuration

vi /usr/local/apache/conf/httpd.conf
and set the DocumentRoot of the domain as

DocumentRoot /home/user/public_html/primary
Save the file and restart the httpd service. BTW, if you don't have root access to your server, ask your hosting provider to change it for you. It's a 2 minute task and hosting provider shouldn't deny your request.
 

enigmas

Registered
Jul 2, 2010
3
0
51
Not sure about the Google indexes but to change the DocumentRoot of a domain, you need to edit the Apache configuration file and edit the value of "DocumentRoot" parameter in the domains VirtualHost entry...
I agree with you, but on hosted domain server you not always have access to the Apache configuration, then the only option is to use .htaccess.
 

enigmas

Registered
Jul 2, 2010
3
0
51
@enigmas, I have struggled with the same problem ...

Worse, I have found that Google indexes my secondary sites like this:

www.primary.co/secondary1.com/ rather than

www.secondary1.com

Any idea why this is happening and how to fis it :confused:
Depends on what do you want to do, for example, if you use the site addon from cPanel, then your url will be www.secondary1.com, but if you use a forward than the rewrite rule should be used.

Sincerely I didn't understood your question.
 

Miraenda

Well-Known Member
Jul 28, 2004
243
5
168
Coralville, Iowa USA
cPanel Access Level
Root Administrator
Not sure about the Google indexes but to change the DocumentRoot of a domain, you need to edit the Apache configuration file and edit the value of "DocumentRoot" parameter in the domains VirtualHost entry. Edit the apache configuration

Code:
vi /usr/local/apache/conf/httpd.conf
and set the DocumentRoot of the domain as

Code:
DocumentRoot /home/user/public_html/primary
Save the file and restart the httpd service. BTW, if you don't have root access to your server, ask your hosting provider to change it for you. It's a 2 minute task and hosting provider shouldn't deny your request.
This will not stay on Apache rebuilds as you cannot directly edit the lines in /etc/httpd/conf/httpd.conf in this way in cPanel. Such manual edits disappear on every EasyApache recompile (/scripts/easyapache) or every Apache rebuild (/scripts/rebuildhttpdconf) that someone runs on the machine. It even has this warning above every single VirtualHost section in that file:

Code:
# DO NOT EDIT. AUTOMATICALLY GENERATED.  IF YOU NEED 
TO MAKE A CHANGE PLEASE USE THE INCLUDE FILES.
To properly edit the DocumentRoot, you would instead go to /var/cpanel/userdata/username/ location (replace username with the actual cPanel username for the account), then edit the file domain.com where domain.com is your primary domain name.

You will see something like this in that file:

Code:
documentroot: /home/username/public_html
You will also see the cgi-bin area in this section:

Code:
scriptalias:
  -
    path: /home/username/public_html/cgi-bin
    url: /cgi-bin/
Simply change both to the right path, then save the file. At that point, copy your existing httpd.conf file, rebuild Apache, then restart Apache. Your site will then start serving from the new document root.

Here are the commands to do those:

Code:
cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.bak100704
/scripts/rebuildhttpdconf
/etc/init.d/httpd restart
You can also look at /etc/httpd/conf/httpd.conf at that point to see it now has the changed DocumentRoot line and cgi-bin path.
 
Last edited: