cPanel Apache Redirects Interface issue | www to non-www not working - main domains

nadav123

Well-Known Member
Mar 2, 2020
159
18
18
Orlando, FL
cPanel Access Level
Root Administrator
Hello everybody, I got an issue here with cPanel redirects.
First, the issue is the main domain, but i try to understand all the problems and how actually the redirects work.

Part1:
Sub Domains:

I create in the interface redirect to the subdomain to the main domain:

# HTTP cPanel | Rewrite / Apache | Subdomains
Code:
RewriteCond %{HTTP_HOST} ^locksmithunit\.es\.locksmithunit\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.locksmithunit\.es\.locksmithunit\.com$
RewriteRule ^(.*)$ "https\:\/\/locksmithunit\.es\/$1" [R=301,L]
now the interface rewrites this code inside htacsses this role to the subdomains,
this working perfectly, in HTTP and HTTPS Version is redirecting the subdomain perfect.
(i only suspicious of the way to redirects and what is recommended by cPanel, for example, HTTP redirect only and not HTTPS, i will note these questions in the end of the explanation)

_____________

Part 2:
Main Domain:

Ok here is a little tricky and unclear, this issue actually turns me a warning light in my head about problem number 1 i noted before Part 2.

When redirecting the main domain things start to be wired:

1. HTTP:X FORWARDED SSL, NOTED INSIDE HTACSSES AND NOT LIKE SUBDOMAINS. ( SUBDOMAINS RULES NEED TO BE REDIRECT BEFORE? HTTP:X FOR SSL RULE?)
2. NOT ABLE TO REDIRECT HTTP IN THE INTERFACE TO THE MAIN DOMAIN. (GET WARNING FROM CPANEL INTERFACE ABOUT LOOP REQUEST, ONLY HTTPS ALLOW)
3. MAIN DOMAIN REDIRECTS NOT WORK WITH STRING: "[OR]". (IT WORK IF I CREATE THE REDIRECTS SEPARATELY ONE BY ONE).

Code main domains redirects. (not working well because [OR] string):
Code:
# HTTPS cPanel | Rewrite / Apache
#RewriteCond %{HTTPS} off
#RewriteCond %{HTTP:X-Forwarded-SSL} !on
#RewriteCond %{HTTP_HOST} ^locksmithunit\.es$ [OR]
#RewriteCond %{HTTP_HOST} ^www\.locksmithunit\.es$
#RewriteRule ^(.*)$ "https\:\/\/locksmithunit\.es\/$1" [R=301,L]

Questions | Final conclusions:
1. %{HTTP:X-Forwarded-SSL} !on -> What is mean about the subdomains? (to redirect them HTTP or HTTPS?)
2. %{HTTP:X-Forwarded-SSL} !on -> Subdomains need to be redirected insitde htacsses before main domain?

3. [OR] string problem -> why mine domain does not work with this string?
3. [OR] string problem -> i note to warning in the interface about the wild card and the main domain:

Code:
Note:

Checking the Wild Card Redirect Box will redirect all files within a directory to the same filename in the redirected directory.
You cannot use a Wild Card Redirect to redirect your main domain to a different directory on your site.
what is mean? is mean I need to put them sepertly? what the actual order?
and how much time I need to put the code: %{HTTP: X-Forwarded-SSL} !on (like each redirect inside htacsses need the SSL code?)

What I did until now but - in the top of the htacssse - (www main domain not redirecting):
Code:
# HTTP cPanel | Rewrite / Apache | Subdomains
RewriteCond %{HTTP_HOST} ^locksmithunit\.es\.locksmithunit\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.locksmithunit\.es\.locksmithunit\.com$
RewriteRule ^(.*)$ "https\:\/\/locksmithunit\.es\/$1" [R=301,L]

# HTTPS cPanel | Rewrite / Apache
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-SSL} !on
RewriteCond %{HTTP_HOST} ^locksmithunit\.es$ [OR]
RewriteCond %{HTTP_HOST} ^www\.locksmithunit\.es$
RewriteRule ^(.*)$ "https\:\/\/locksmithunit\.es\/$1" [R=301,L]

by the way, I force HTTPS throw the cPanel domain interface. (if it helps with this info).
The code above is Redirects from the cPanel interface, i didn't edit manually the code or something.

The only thing i did this: redirect first the subdomains to the main domain in the interface.

And then i create the redirect for the main domain (www and non-www redirects) as you see in the code.

if someone can tell me what is the right order, and the protocol for the subdomains (subdomains final URL in HTTPS? or HTTP? for subdomains?)
and explain why the subdomain does not have %{HTTP:X-Forwarded-SSL} !on, and if i actually need it for the subdomains, it is more then great :)

Be more than great if someone can order this code and noted it here in a message (with keeping the original code of cPanel Redirects more or less).
 

nadav123

Well-Known Member
Mar 2, 2020
159
18
18
Orlando, FL
cPanel Access Level
Root Administrator
I Found something where strange, CNAME records not redirecting!
example:

mail.locksmithunit.com/robots.txt

is need to locksmithunit.com/txt.

is maybe the TWAEK in the WHM?
 

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
17,470
2,843
363
cPanel Access Level
Root Administrator
Hey there! I actually would not use the redirects interface for this work. I would go to cPanel >> Domains and then choose the "Force HTTPS Redirect" option slider next to each domain you wanted to redirect. This avoids the issue of having to setup multiple redirects manually in the redirect page.

Can you try that and see if that gives you better results? I'd recommend undoing the previous work before making those changes.
 

nadav123

Well-Known Member
Mar 2, 2020
159
18
18
Orlando, FL
cPanel Access Level
Root Administrator
I did this as well and this does not redirect the subdomains to the main domains...

and as I told you, I notice all the CNAME Records are not actually redirected as well... so I got lost a little bit.


currently, now i bring back the redirection and the site redirect from apache but i sure i have a problem here and i don't do it as should be.


If everything was fine, the CNAME records redirected.

but is not redirect automatically the subdomains to the main domain.
(and i tried what you offer is not work, is only make the HTTPS but not redirect the subdomains and the www domains...)

cPanel support not answer, i open 4 tickets nobody answer, so i give up.
hope i will find a solution here..
 

nadav123

Well-Known Member
Mar 2, 2020
159
18
18
Orlando, FL
cPanel Access Level
Root Administrator
ok, i found this with the hosting:

is means cpanel aware of on the issue...
this what I build in apache redirect and this menu:

Code:
# HTTPS cPanel | Rewrite / Apache | Main Domain
RewriteCond %{HTTPS} off
#RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteCond %{HTTP:X-Forwarded-SSL} !on
RewriteCond %{HTTP_HOST} ^locksmithunit\.cat$
RewriteRule ^(.*)$ "https\:\/\/locksmithunit\.cat\/$1" [R=301,L]

# HTTPS cPanel | Rewrite / Apache | Email Subdomains
RewriteCond %{HTTP_HOST} ^mail.locksmithunit\.cat$ [OR]
#RewriteCond %{HTTP_HOST} ^www\.mail.locksmithunit\.cat$ [OR]

# HTTPS cPanel | Rewrite / Apache | Main Domain | www -> non-www
RewriteCond %{HTTP_HOST} ^www\.locksmithunit\.cat$ [OR]

# HTTPS cPanel | Rewrite / Apache | Subdomains
RewriteCond %{HTTP_HOST} ^locksmithunit\.cat\.locksmithunit\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.locksmithunit\.cat\.locksmithunit\.com$

# HTTPS cPanel | Final URL
RewriteRule ^(.*)$ "https\:\/\/locksmithunit\.cat\/$1" [R=301,L]

and have this too (because the HTTPS in the interface is ON):

Code:
# HTTPS cPanel | Rewrite / Apache | Email Subdomains
RewriteCond %{HTTP_HOST} ^mail.locksmithunit\.cat$ [OR]
#RewriteCond %{HTTP_HOST} ^www\.mail.locksmithunit\.cat$ [OR]

# HTTPS cPanel | Rewrite / Apache | Main Domain | www -> non-www
RewriteCond %{HTTP_HOST} ^www\.locksmithunit\.cat$ [OR]

# HTTPS cPanel | Rewrite / Apache | Subdomains
RewriteCond %{HTTP_HOST} ^locksmithunit\.cat\.locksmithunit\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.locksmithunit\.cat\.locksmithunit\.com$

# HTTPS cPanel | Final URL
RewriteRule ^(.*)$ "https\:\/\/locksmithunit\.cat\/$1" [R=301,L]
Both of them do the job.
but I pretty sure the order needs to be different.

For example (I not sure):
Code:
# HTTPS cPanel | Rewrite / Apache | Email Subdomains
RewriteCond %{HTTP_HOST} ^mail.locksmithunit\.cat$ [OR]

# HTTPS cPanel | Rewrite / Apache | Main Domain | www -> non-www
RewriteCond %{HTTP_HOST} ^www\.locksmithunit\.cat$ [OR]

# HTTPS cPanel | Rewrite / Apache | Subdomains
RewriteCond %{HTTP_HOST} ^locksmithunit\.cat\.locksmithunit\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.locksmithunit\.cat\.locksmithunit\.com$

# HTTPS cPanel | Final URL
RewriteRule ^(.*)$ "https\:\/\/locksmithunit\.cat\/$1" [R=301,L]

# HTTPS cPanel | Rewrite / Apache | Main Domain
RewriteCond %{HTTPS} off
#RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteCond %{HTTP:X-Forwarded-SSL} !on
RewriteCond %{HTTP_HOST} ^locksmithunit\.cat$
RewriteRule ^(.*)$ "https\:\/\/locksmithunit\.cat\/$1" [R=301,L]

maybe even to put the last block in mod_rewrite.c IF:

Code:
# HTTPS cPanel | Rewrite / Apache | Email Subdomains
RewriteCond %{HTTP_HOST} ^mail.locksmithunit\.cat$ [OR]

# HTTPS cPanel | Rewrite / Apache | Main Domain | www -> non-www
RewriteCond %{HTTP_HOST} ^www\.locksmithunit\.cat$ [OR]

# HTTPS cPanel | Rewrite / Apache | Subdomains
RewriteCond %{HTTP_HOST} ^locksmithunit\.cat\.locksmithunit\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.locksmithunit\.cat\.locksmithunit\.com$

# HTTPS cPanel | Final URL
RewriteRule ^(.*)$ "https\:\/\/locksmithunit\.cat\/$1" [R=301,L]

# HTTPS cPanel | Rewrite / Apache | Main Domain
<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} off
#RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteCond %{HTTP:X-Forwarded-SSL} !on
RewriteCond %{HTTP_HOST} ^locksmithunit\.cat$
RewriteRule ^(.*)$ "https\:\/\/locksmithunit\.cat\/$1" [R=301,L]
</IfModule>

Can be subdomains need be redirects HTTP?
look on my examples, tell me what is the best.