Skip to main content

Can't redirect www to domain

Comments

29 comments

  • cPRex Jurassic Moderator
    Hey there! Would this be a WordPress site? The siteurl value along with various plugins can determine how redirection happens, and that is outside both Apache and .htaccess. A tool such as the ReallySimpleSSL plugin is great to take care of those issues. If this is another CMS-style site, I'd recommend the same thing - looking through the site code itself and other settings to see if that is where the issue happens.
    0
  • Spirogg
    No matter how I try I can not redirect www Set a redirect in cpanel - picked the main domain - set it to only redirect www Nothing happens. It's like the entry in htaccess doesn't exist.

    what is the outcome of what your trying to do ? so you want your domain to be https://domain.com
    and if they type www.domain.com
    you want it to redirect to https://domain.com
    is this correct?
    0
  • Spirogg
    Hey there! Would this be a WordPress site? The siteurl value along with various plugins can determine how redirection happens, and that is outside both Apache and .htaccess. A tool such as the ReallySimpleSSL plugin is great to take care of those issues. If this is another CMS-style site, I'd recommend the same thing - looking through the site code itself and other settings to see if that is where the issue happens.

    @cPRex i tried to do both domain http://www.domain.com
    and domain.com
    via cPanel to https//:domain.com when i type http://domain
    http://www.domain
    redirects to https://domain
    when i type in https://www.domain
    it stays at https://www.domain
    but should redirect to https://domain
    is this a bug I've also tested only redirect www to https://domain
    and if it has https://www.domain
    it will not redirect so if an user want's his domain to redirect to https://domain.com
    in cPanel it does not work. cause if you type https://www.domain.com
    will not redirect to https://domain.com
    0
  • cPRex Jurassic Moderator
    @Spirogg - I'd need some more details, but it likely isn't a wildcard redirect match so it won't override the www if manually included. You'd need to use .htaccess rules to make that happen. @vincentg - it doesn't sound like this is a cPanel issue, but a problem with the application itself. If you have root access to the machine we'd be happy to take a look at the system for you to ensure the webserver and redirection processes are working well if you're able to submit a ticket.
    0
  • vincentg
    For years the site was working fine but recently it crashed. This due to a redirect I had to redirect http:// to https:// This 2 lines in htaccess caused it to loop Happened a short time ago. Had the tech at Multacom look it over and he was at a loss. Neither of us could figure this out All that's in the php script that references https is one line. Business Website Hosting Services | Reseller Web Hosting - New York, USA"/> Other than that there is nothing but html page code I wrote it so I know what's in it. To resolve the loop problem we removed the two lines to redirect http to https there is only three redirects left other than # 400 - Bad Request ErrorDocument 400 /error.php # 401 - Unauthorized ErrorDocument 401 /error.php # 402 - Payment Required ErrorDocument 402 /error.php # 403 - Forbidden ErrorDocument 403 /error.php # 404 - Not Found ErrorDocument 404 /error.php There has been a added feature in cpanel for Domain A check box to redirect to SSL I noticed it doesn't add an entry to htaccess when checked. where does it save it's setting? Maybe something there is causing my problem. No need for you to access the server - just clue me in on where to check. It's not a bad entry in httpd.conf as that's perfect. It's not from htaccess and it's not from index.php The guys at Multacom are top notch and I'm not too bad either. What ever is causing this problem is not simple.
    0
  • vincentg
    Have a second site on server with same problem Auto redirecting to SSL and can't redirect www In checking I find some work and some don't. From where I stand the problem is without a doubt due to this new setting in Domains My gut tells me that it's on even though it shows off Where does it save the setting?
    0
  • Spirogg
    Have a second site on server with same problem Auto redirecting to SSL and can't redirect www In checking I find some work and some don't. From where I stand the problem is without a doubt due to this new setting in Domains 77869 My gut tells me that it's on even though it shows off Where does it save the setting?

    theres more info about WP as well in this blog, but at least we find the area that it is stored in bold below. Domains interface in cPanel (Home >> Domains), there"s an option to enable Force HTTPS Redirection from the insecure version (HTTP) to the secure version (HTTPS) with a toggle switch. This information is stored in the account"s user data files (/var/cpanel/userdata), and the redirection is built into the domain"s vhost configuration. ]https://blog.cpanel.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-11-at-10.37.24-AM.png
    All domains with valid SSL certificates can have redirection enabled. Aliases (historically called Parked Domains) will inherit their redirection status from their parent domain. No longer will a manual .htaccess redirect, plugin, or Apache configuration update be required. Now, an end-user can toggle a switch to redirect visitors to the secured version of your sites! Kind Regards, Spiro
    0
  • Spirogg
    [root@server1 ~]# cd /var/cpanel/userdata/cpanel-username
    then cat cpanel-username
    at the very bottom you will see it I turned it ON servername: domain.com ssl: 1 ssl_redirect: 1 usecanonicalname: 'Off' user: cpanel-username userdirprotect: ''
    I turned it OFF servername:domain.com ssl: 1 ssl_redirect: '' usecanonicalname: 'Off' user: cpanel-username userdirprotect: ''
    i am using Almalinux and cPanel 102.0.15 just fyi so it seems it turns it off here. but this is only the settings area. so need to find in maybe apache vhost file the actual rule ? still looking
    0
  • vincentg
    Spirogg - thank you for the examples as that would have been my next question ssl_redirect: '' is missing Have servername: domain.com ssl: 1 usecanonicalname: 'Off' user: user_name userdirprotect: '' Every account is same so this I think explains it Doesn't matter what the setting is - on or off, the setting entry ssl_redirect: is not there at all Now how do we fix it?
    0
  • Spirogg
    0
  • Spirogg
    0
  • Spirogg
    @vincentg What version cPanel are you running. Sorry if you posted this I"m on my iPhone so
    0
  • Spirogg
    Do you have a test account I saw somewhere in a post that there is a rebuild user data maybe if you have a test account and do t see that file possibly it might rebuild and issue would be gone. ? Let me find that link
    0
  • Spirogg
    @vincentg Ok I found this link. For resting user data file. I believe this might help But you can maybe make a copy of your file and try this and then if anything is wrong you can revert back to original. Here is the link
    0
  • Spirogg
    @vincentg Ps. I wonder if you add the part that"s missing by nano into that file and just add ssl_redirect: '' Restart Apache and see if that works. also go to domain and click force On then com back to userdata file and see if it changed to ssl_redirect: '1' Then go back and turn it OFF And see if it changes back to ssl_redirect: '' Then you know it"s working ? Better trying this first then doing the user data update script. ?
    0
  • vincentg
    Ran upcp --force Now we have this setting But still it's same Can't do a redirect away from www and no matter the setting it auto switches to ssl Is this a problem only on this server or do others have it too? cPanel & WHM v102.0.15 (STANDARD) Operating System AlmaLinux v8.6.0 Intel(R) Xeon(R) CPU E5-1650 v3 @ 3.50GHz
    0
  • Spirogg
    Ran upcp --force Now we have this setting But still it's same Can't do a redirect away from www and no matter the setting it auto switches to ssl

    I"m not following you on can"t do a redirect away from www Are you meaning you want to redirect to domain.com vs www.domain.com
    0
  • vincentg
    yes In redirects - add domain and set redirect only with www to
    0
  • Spirogg
    yes In redirects - add domain and set redirect only with www to
    0
  • Spirogg
    1) from www to Non-www redirection I have added here seven examples script for www to Non-www redirection. # Example - 1 # RewriteEngine On RewriteCond %{HTTP_HOST} ^www\.domain\.com [NC] RewriteRule ^(.*)$ https://domain.com/$1 [L,R=301]
    # Example - 2 # RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
    # Example - 3 # RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^/(.*)$ http://%1/$1 [R]
    # Example - 4 # RewriteEngine On RewriteCond %{HTTP_HOST} !^domain\.com RewriteRule (.*) https://domain.com/$1 [R=301,L]
    # Example - 5 # RewriteEngine On RewriteCond %{HTTP_HOST} !^domain\.com$ [NC] RewriteRule ^(.*)$ https://domain.com/$1 [R=301,L]
    # Example - 6 # RewriteEngine on RewriteCond %{HTTP_HOST} ^www\.domain\.com [NC] RewriteRule (.*) https://domain.com/$1 [R=301,L]
    # Example - 7 # RewriteEngine on RewriteCond %{HTTP_HOST} ^www\.(([a-z0-9_]+\.)?domain\.com)$ [NC] RewriteRule .? http://%1%{REQUEST_URI} [R=301,L]
    2) from Non-www to www redirection I have added here five examples script for www to Non-www redirection. # Example - 1 # RewriteEngine On RewriteCond %{HTTP_HOST} ^(?!www\.)(.+) [NC] RewriteRule ^(.*) http://www.%1/$1 [R=301,NE,L]
    # Example - 2 # RewriteEngine On RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
    # Example - 3 # RewriteEngine on RewriteCond %{HTTP_HOST} ^domain\.com [NC] RewriteRule (.*) https://www.domain.com/$1 [R=301,L]
    # Example - 4 # RewriteEngine on RewriteCond %{HTTP_HOST} !^www\.domain\.com RewriteRule (.*) https://www.domain.com/$1 [R=301,L]
    # Example - 5 # RewriteEngine on RewriteCond %{HTTP_HOST} ^([a-z.]+)?domain\.com$ [NC] RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule .? http://www.%1example.com%{REQUEST_URI} [R=301,L]
    3) https redirection For https redirection form www to Non-www and Non-www to www add, s to any of the above examples to trick it. 4) For sub-folder redirection For sub folder redirection. Like if you have redeveloped your website and the contents are stored at "/demo" folder and if you want that to be redirected to the main domain in sub folder, then try any of the below examples. # Example - 1 # RewriteEngine On RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^(.*)$ http://%1/demo/$1 [R=301,L]
    # Example - 2 # RewriteEngine On RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC] RewriteRule ^$ http://%{HTTP_HOST}/demo/index.php [R,L]
    # Example - 3 # RewriteEngine On RewriteRule ^$ /demo [L]
    # Example - 4 # RewriteEngine on RewriteCond %{HTTP_HOST} ^domain\.com$ RewriteRule (.*) https://www.domain.com/$1 [R=301,L] RewriteRule ^$ demo [L] or RewriteRule ^$ /demo [L,R=301]
    # Example - 5 # RewriteEngine On RewriteRule ^(.*)$ /demo/$1 [L]
    # Example - 6 # RewriteEngine on RewriteCond %{REQUEST_URI} ^/$ RewriteRule (.*) https://www.domain.com/demo [R=301,L]
    # Example - 7 # RewriteEngine On RewriteCond %{HTTP_HOST} ^(www.)?domain.com$ RewriteRule ^(/)?$ demo [L]
    # Example - 8 # RewriteEngine On RewriteRule !^demo/ /demo%{REQUEST_URI} [L,R=301]
    # Example - 9 # RewriteEngine on RewriteCond %{HTTP_HOST} ^(www.)?domain.com$ RewriteCond %{REQUEST_URI} !^/demo/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /demo/$1 RewriteCond %{HTTP_HOST} ^(www.)?domain.com$ RewriteRule ^(/)?$ demo/index.php [L]
    # Example - 10 # Options -Indexes +SymLinksIfOwnerMatch RewriteEngine on RewriteBase / RewriteCond %{REQUEST_URI} !^/demo/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /demo/$1 [L]
    # Example - 11 # Options -Indexes +SymLinksIfOwnerMatch RewriteEngine on RewriteBase / RewriteCond %{REQUEST_URI} !^/demo/ RewriteCond %{HTTP_HOST} ^(www\.)?domain\. RewriteRule ^(.*)$ /demo/$1 [L]
    options to try also for anyone else needed to try .htaccess for redirects. Spiro
    0
  • Spirogg
    this one seems to work really well on my site. no matter what I type, it will always redirect to non-www https:// domain.com RewriteEngine On RewriteCond %{HTTPS} off [OR] RewriteCond %{HTTP_HOST} ^www\. [NC] RewriteRule ^ https://domain.com%{REQUEST_URI} [L,NE,R=301]
    0
  • vincentg
    RewriteEngine on AuthName httpsend.com # php -- BEGIN cPanel-generated handler, do not edit # Set the "ea-php74" package as the default "PHP" programming language. AddHandler application/x-httpd-ea-php74 .php .php7 .phtml # php -- END cPanel-generated handler, do not edit RewriteCond %{HTTPS} off RewriteCond %{HTTP:X-Forwarded-SSL} !on RewriteCond %{HTTP_HOST} ^www\.httpsend\.com$ RewriteRule ^/?$ "https\:\/\/httpsend\.com\/" [R=301,L] That's all that's there Cpanel created that redirect I tried other ways of doing it if I remove RewriteCond %{HTTPS} off RewriteCond %{HTTP:X-Forwarded-SSL} !on it works for www but it still redirect to https: This is not working proper. It should not matter what way you do a redirect. If you do it correct it should work. So the setting in domain is off there is no RewriteCond %{HTTPS} off condition nothing telling it to redirect to https:// The redirect that cpanel makes should work. That's what it's there for - so techs like us don't have to manually do it.
    0
  • vincentg
    If I only have a www redirect it works Add others and it stops working. It erratic behavior Am tired of trying to make a broken system unbroken
    0
  • vincentg
    We have more info on it. It seems that if you have an account that had no redirects ever created it works normal But if you create any type of redirect it will auto add redirection to SSL Remove the redirect and the auto redirect to ssl remains I believe this is a mistake from cpanel This server is a new install cPanel & WHM v102.0.15 (STANDARD) AlmaLinux v8.6.0
    0
  • cPRex Jurassic Moderator
    Since this has been an issue for two pages now, it's likely time to make a ticket. If you're not able to do that, could you provide us with specific reproduction steps so I can do some testing on my end?
    0
  • Helena Rox
    Have a second site on server with same problem Auto redirecting to SSL and can't redirect www In checking I find some work and some don't
    0
  • cPRex Jurassic Moderator
    @Helena Rox - could you submit a ticket to our support team so we can check this out?
    0
  • alekses
    In my case, adding the formula to the .htaacess file helped, thanks for the replies on the topic! [url=https://sex-telefon24.pl/blog]https://sex-telefon24.pl/wp-content/uploads/2022/06/seks-telefon.png
    0

Please sign in to leave a comment.