1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

XF 1.2 www. Or non www.

Discussion in 'XenForo Questions and Support' started by oman, Jul 19, 2013.

  1. oman

    oman Well-Known Member

    I remember I configured something to help force a www on the domain when you type it without. I need to do re directs on my site.

    Could you please tell me how I can do both options:

    a) Force www. on the domain

    b) Force domain without www.

    I haven't decided which one I'll do yet, but soon I will so both options would be great.
     
  2. Brogan

    Brogan XenForo Moderator Staff Member

  3. Tracy Perry

    Tracy Perry Well-Known Member

    Further, it will be entirely dependent on whether you are using nginx or Apache2 as your web server. Each is configured differently.
    This will (in nginx) rewrite the www. to the domain base
    Code:
    server {
        listen 80;
        server_name www.yourdomain.com domain.com;
        return 301 http://domain.com$uri;
    }
    
    Or this should do the opposite and force yourdomain.com to www.yourdomain.com
    Code:
    server {
        listen 80;
        server_name www.domain.com domain.com;
        return 301 http://www.domain.com$uri;
    }
    
     
  4. RoldanLT

    RoldanLT Well-Known Member

    Your code doesn't work for me, this is what I'm using:

    Code:
    server {
      server_name domain.com;
      return 301 $scheme://www.domain.com$request_uri;
    }
    server {
      server_name www.domain.com;
      [...]
    }
     
  5. Tracy Perry

    Tracy Perry Well-Known Member

    It may be because I have 5 domains mapped to sayapple.com (which is the example I pulled from). There are several entries above and below the original one I posted. I don't remap to www, so was not sure if that would work or not, therefore why I stated that it should work. If it was a singular domain, then yes, it would be different. The listen 80 is just in case I decide that I want to run a site on a different port for testing (I have a default config file I copy over). I know the first one works on my remapping (www.apple4me.net, www.apple4me.us, www.apple4me.org and www.justsayapple.com as well as the non www prefixed ones). I had assumed that someone that was familiar with nginx would know that they have to have their default server defined as the final one (since nginx precedence is from top down in the config file).
    Also, since I don't serve any https, I just hard code the http, as that all the $scheme does is detect either the request is http or https.
    I should have pulled from my bogboys.com one, as their are no additional domains listed for it, and just checked at
    Code:
    server {
        listen 80;
        server_name bogboys.com;
        return 301 http://www.bogboys.com$uri;
    }
    
    server {
        listen 80;
        server_name www.bogboys.com;
    works, which is what you have reflected - minus the $scheme prefix.
     
    Last edited: Jul 19, 2013
  6. oman

    oman Well-Known Member

  7. Tracy Perry

    Tracy Perry Well-Known Member

    It shouldn't, as the actual links remain the same. All you are doing is redirecting WWW to a non WWW domain.
     
    oman likes this.
  8. trantai

    trantai Member

    Recommend to use Non www
    Our site changes to Non www, and it runs Ok!
    (www.vfpress.vn)
     
    oman likes this.

Share This Page