Redirects & Rewrites - .htaccess & cPanel - questions

globus999

Registered
Jun 21, 2013
1
0
1
cPanel Access Level
Website Owner
I am trying to understand how redirects & rewrites work in a shared-hosting configuration considering that there are two different functions going on simultaneously, this is cPanel and .htaccess manual scripting. There are 4 possibilities:

1 - My original domain: this is the domain I opened a shared account with. If I set up apps in a different directory than public_html then I need to manually re-direct/re-write to that directory through .htaccess. I cannot do this through cPanel. This correct?

2 - Parked Domains: I can go through cPanel, which will write into the .htaccess pointing to the appropriate directory I selected in the Parked Domain page. But what will happen if I write into .htaccess directly and not go through cPanel? I am assuming that there will be a disconnect since the nameservers will be pointing to my hosting company but the local DNS would not resolve to my public_html directory since cPanel did not set it up. Therefore, it is a bad idea to write into .htaccess directly for Parked Domains, correct?

3 - Add-on Domains: I am forced to go through cPanel only since it does not write into .htaccess. I am guessing that cPanel adds a resolution for that domain to my public_html directory. If I try to write into .htaccess directly, again, there will be a disconnect since the nameservers will be pointing to my hosting company but the local DNS would not resolve to my public_html directory since cPanel did not set it up. Therefore, it is a bad idea to write into .htaccess directly for Add-On Domains, correct?

4 - Sub-Domains: same as Add-On Domains.

I don't quite get it why cPanel would write into .htacces for Parked, but not for Add-Ons or Subs.

But, more importantly, can I trust cPanel? For example, for a main domain redirect, I would have the following code:

RewriteCond %{THE_REQUEST} /s1/j1/
RewriteRule ^s1/j1/(.*) http://www.example1.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^(*\.example1\.*)$ [NC]
RewriteCond %{HTTP_HOST} !^(www\.example1\.com)$ [NC]
RewriteRule (.*) http://www.example1.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^www.example1.com$
RewriteCond %{REQUEST_URI} !^/s1/j1/
RewriteRule (.*) /s1/j1/$1 [L]

which would take care of all the nuances dealing with improper namings, HTTP v1.0, etc,, in addition to the rewrite.

However, for Parked, Add-Ons and Subs, I have no clue if all these nunances are taken care of by cPanel, or do I need to add into the .htaccess file?
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,268
463
Hello :)

The "Redirects" option in cPanel utilizes the .htaccess file for creating redirects. It's simply a visual method of creating a redirect for those that do not wish to manually edit a .htaccess file. Allow me to address each question individually:

1. It's not possible to modify the document root for the primary domain name via cPanel. Instead, you should consult with your hosting provider so they can update the default document root for the domain name by editing the following file:

Code:
/var/cpanel/userdata/$user/$domain.com
Then, the Apache configuration file can be rebuilt via:

Code:
# /scripts/rebuildhttpdconf
Otherwise, yes, a manual redirect in the .htaccess file would be a workaround.

2. Yes, you should create the parked domain name via cPanel to ensure the appropriate entries are added in the Apache configuration file. Manual redirects after creating the parked domain name via cPanel can be made through cPanel or by manually adjusting the .htaccess file.

3. You should create addon domain names through cPanel to ensure the appropriate additions to the Apache configuration file are made. Manual redirects after creating the addon domain name via cPanel can be made through cPanel or by manually adjusting the .htaccess file.

4. Yes, addon domain names are essentially created as subdomains with cPanel. Thus, answer number three also applies to subdomains.

Thank you.