SOLVED how to redirect domain/folder to subdomain to non-www in cpanel not working ?

Spirogg

Well-Known Member
Feb 21, 2018
700
162
43
chicago
cPanel Access Level
Root Administrator
hi,

I am using cPanel 84.08 VPS cloud - CentOS 7.7 MariaDB 10.3

I am having an issue with subdomain redirects

so I have a domain called: example.com
I have this set to https:// and to redirect to www.example.com working great...

I then create a sub domain: work.example.com

i then turn on https:// then go to redirects and try to redirect the subdomain without www. but it throws error, because it is the same path / Folder
so then I go back to redirect and select : example.com
then I add the folder /work
then I add http://work.example.com
then I select: Only redirect with www.

it allows this redirect..

I then go to http://example.com/work but it doesn't redirect
so i select: redirect with or without www

and that seems to work but, the only issue is that I can type http://www,work.example.com and it doesn't redirect to https://work.example.com

So not sure... how I can achieve both of these redirects ?

I want anyone who types in http://www.work.example.com to redirect to https://work.example.com
also if someone types in http://example.com/work or http://www.example.com/work or https://www.example.com/work

to redirect to https://work.example.com



is this redirect I am mentioning even possible? to redirect the folder and the www to non www in work.example.com subdomain via cPanel redirect?

hope i didn't confuse anyone I am trying to write as much as possible so you can understand what I am trying to accomplish

thanks in advance for anyone who can help using redirect via cPanel or I can just use htaccess with some code to make this work correctly

Spiro
 

cPanelLauren

Product Owner II
Staff member
Nov 14, 2017
13,266
1,301
363
Houston
Hello @Spirogg

I'm not able to replicate this.
  • I have a subdomain called 123.mydomain.us
  • Its document root is in /home/myuser/public_html/123
  • the root domain mydomain.us is forced to redirect to https
  • When I add a redirect through cPanel the following is added to the .htaccess for the subdomain:
    Code:
    RewriteCond %{HTTP_HOST} ^123\.mydomain\.us$ [OR]RewriteCond %{HTTP_HOST} ^www\.123\.mydomain\.us$
    RewriteRule ^/?$ "https\:\/\/mydomain\.us\/" [R=301,L]
  • I tested by entering in the following:
  • All of them redirected successfully to mydomain.us -&nbspDomain Names Resources and Information.
Are you sure you're not encountering caching?
 

Spirogg

Well-Known Member
Feb 21, 2018
700
162
43
chicago
cPanel Access Level
Root Administrator
Hi @cPanelLauren

I did clear cache. And still have this issue. So my setup is different.

So maybe I can explain a little more.
I have setup work.domain.us have enabled to force https://

But I want to make sure that whom ever goes to www.work.domain.us or www.domain.us/work or domain.us/work will be redirected to

Not domain.us

Thanks for your help
 
Last edited:

cPanelLauren

Product Owner II
Staff member
Nov 14, 2017
13,266
1,301
363
Houston
Hello,

In my instance I forced https on the destination domain only - since anything else is being redirected to it. I realize it didn't show very visibly on the link.


What's the redirect look like in the .htaccess file?
 

Spirogg

Well-Known Member
Feb 21, 2018
700
162
43
chicago
cPanel Access Level
Root Administrator
First I have forced https for both domain.com and work.domain.com

Then I redirected domain.com to www.domain.com

Then I redirected domain.com/work
To http://work.domain.com

Here is the code below.


Code:
RewriteCond %{HTTP_HOST} ^domain\.com$
RewriteRule ^/?$ "http\:\/\/www\.domain\.com\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^domain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domain\.com$
RewriteRule ^work\/?$ "http\:\/\/work\.domain\.com\/" [R=301,L]

I think this is working now
except if someone enters http://www.work.domain.com it won't redirect to http://work.domain.com

Which I don't think anyone will type www.work.domain.com

unless you know of a way to redirect the www in the subdomain also ?

The reason I ask, is that the script I will be using for work.domain.com will only work properly from http or https work.domain.com it will not work properly if someone enters http https www.work.domain.com from a css and login stand point. Has to be one or the other either www.work.domain.com Or just work.domain.com

Thanks for all your help
Regards,
Spiro
 

cPanelLauren

Product Owner II
Staff member
Nov 14, 2017
13,266
1,301
363
Houston
Hi @Spirogg

But the end goal is for them to end up at https://work.domain.com right? If you remove forced redirection to https from everything but work.domain.com and then set up the .htaccess redirect rule the way I have it, it should function to move everything to https://work.domain.com with or without https and with or without www


Code:
RewriteCond %{HTTP_HOST} ^123\.mydomain\.us$ [OR]
RewriteCond %{HTTP_HOST} ^www\.123\.mydomain\.us$
RewriteRule ^/?$ "https\:\/\/mydomain\.us\/" [R=301,L]
 
  • Like
Reactions: Spirogg

Spirogg

Well-Known Member
Feb 21, 2018
700
162
43
chicago
cPanel Access Level
Root Administrator
Ok this worked awesome your the BEST !!!!! THANKS SO MUCH

I was breaking my head trying to figure it out. Thanks

Solved

Regards,

Spiro
 
  • Like
Reactions: cPanelLauren