Welcome Guest. Please Login or Register  


You are here: Index > Webuzo > General Support > Topic : Force www. on primary domain



Threaded Mode | Print  

 Force www. on primary domain (3 Replies, Read 851 times)
erile
Group: Member
Post Group: Working Newbie
Posts: 51
Status:
Hello,

I would like to force www.domain.com for domain.com. So, I added an extra conf from Webuzo about domain.com with this content:
Code
if ($server_name = 'domain.com'){
  return 301 https://www.$server_name$request_uri;}

But it enters in infinite loop raising an ERR_TOO_MANY_REDIRECTS error.

First, I thgough it was due to the fact I also added code to force SSL whatever the domain in /usr/local/apps/nginx/etc/conf.d/common, like this:
Code
if ($scheme = 'http'){
      return 301 https://$server_name$request_uri;}

Then, searching for a solution I saw that the the recommended way from Nginx is to provide two separated server blocks for domain.com and www.domain.com, then only add the redirection in the domain.com one. Something like this:
Code
server {
  server_name www.domain.com;
  ...
}
server {
  server_name domain.com;
  return 301 https://www.$server_name$request_uri;
  ...
}

And knowing port 80 and 443 are already two blocks, it could gives four server blocks.

How to achieve this, knowing Webuzo keeps control on webuzoVH.conf containing the server blocks? Or is there another way to do it with Webuzo?

TIA

-----------------------
OpenVZ VPS, CentOS 7, Webuzo Premium / Desktop and full-stack dev w/ C, C++, Python, Perl, javascript...
IP: --   

Force www. on primary domain
erile
Group: Member
Post Group: Working Newbie
Posts: 51
Status:
Unless mistake (I'll re-test on monday), I think I found the right way to achieve the goal: force both SSL and www whatever the scheme, knowing Webuzo doesn't allow to separate www and non-www in two server blocks. It seems http://domain.com, http://www.domain.com and https://domain.com (the most problematic one) ) are all redirected to https://www.domain.com now. Apparently no infinite loop this way.

I added an extra conf for domain.com from Webuzo > Domain > Extra Configuration with this content:
Code

if ($scheme = http) {
    return 301 https://www.domain.com$request_uri;
}
if ($http_host = domain.com){
    return 303 https://www.domain.com$request_uri;
}

It may help another one someday...
Solved (it seems)!

-----------------------
OpenVZ VPS, CentOS 7, Webuzo Premium / Desktop and full-stack dev w/ C, C++, Python, Perl, javascript...
IP: --   

Force www. on primary domain
Dhanya
Group: Softaculous Team
Post Group: Working Member
Posts: 153
Status:
Hi,

In order to redirect http://domain.com on https://www.domain.com you need to add the following code block only in the extra conf:
if ($scheme = http) {
        return 302 https://www.$server_name$request_uri;
}

Let us know if you need any further information from us.
IP: --   

Force www. on primary domain
erile
Group: Member
Post Group: Working Newbie
Posts: 51
Status:
I know this, Dhanya, but it was not the question. If you well read the thread, the problem was not to simply force https, but also to force www even when the scheme is already https... Look around everywhere, there's no way, unless with two separated server block for www and non-www, or the solution I provide above. All others solutions induce an infinite loop of redirections.

The question was, how to redirect both http://domain.com, http://www.domain.com AND https://domain.com towards https://www.domain.com?

Try on your part, you'll see better what I mean...

-----------------------
OpenVZ VPS, CentOS 7, Webuzo Premium / Desktop and full-stack dev w/ C, C++, Python, Perl, javascript...
IP: --   

« Previous    Next »

Threaded Mode | Print  



Jump To :


Users viewing this topic
2 guests, 0 users.


All times are GMT. The time now is September 23, 2019, 7:36 am.

  Powered By AEF 1.0.8 © 2007-2008 Electron Inc.Queries: 11  |  Page Created In:0.463