Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login

    Redirect www to non www

    Scheduled Pinned Locked Moved pfSense Packages
    8 Posts 4 Posters 3.0k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ?
      A Former User
      last edited by A Former User

      Hey,

      My website is now accessible through two links:
      www.website.com
      website.com

      I would like the site to be accessible only through website.com and that www.website.com will therefore refer to website.com.

      I use haproxy for load balacing of my two web servers. ssl offloading is used upon arrival

      I have visited a lot of sites but nowhere is there really a working answer, so maybe someone here knows the answer

      gr
      rock95

      1 Reply Last reply Reply Quote 0
      • dragoangelD
        dragoangel
        last edited by dragoangel

        Cleantext HAproxy config:

        acl www.somedomain.com var(txn.txnhost) -m str -i www.somedomain.com
        http-request redirect code 301 location https://somedomain.com%[url]  if  www.somedomain.com
        

        Sample of how looks Frontend Actions Table Record (second line):
        redirect-sample.png
        For better understanding better read https://cbonte.github.io/haproxy-dconv/ and use HAProxy 1.8.x version on pfSense wich package marked as: haproxy-devel

        Latest stable pfSense on 2x XG-7100 and 1x Intel Xeon Server, running mutiWAN, he.net IPv6, pfBlockerNG-devel, HAProxy-devel, Syslog-ng, Zabbix-agent, OpenVPN, IPsec site-to-site, DNS-over-TLS...
        Unifi AP-AC-LR with EAP RADIUS, US-24

        ? 1 Reply Last reply Reply Quote 1
        • ?
          A Former User @dragoangel
          last edited by

          @dragoangel it works, nice! thank you so much 👌

          1 Reply Last reply Reply Quote 0
          • O
            Overlord
            last edited by

            @dragoangel said in Redirect www to non www:

            http-request redirect code 301 location https://somedomain.com%[url] if www.somedomain.com

            Hey guys - and how it that reverse? I would like to have a redirect from domain.tld to www.domain.tld.

            www.domain.tld is working fine - but domain.tld runs in the failure site of HAProxy

            Thanks for helping!

            dragoangelD 1 Reply Last reply Reply Quote 0
            • dragoangelD
              dragoangel @Overlord
              last edited by

              @Overlord show your config, in pm if you want

              Latest stable pfSense on 2x XG-7100 and 1x Intel Xeon Server, running mutiWAN, he.net IPv6, pfBlockerNG-devel, HAProxy-devel, Syslog-ng, Zabbix-agent, OpenVPN, IPsec site-to-site, DNS-over-TLS...
              Unifi AP-AC-LR with EAP RADIUS, US-24

              G 1 Reply Last reply Reply Quote 0
              • G
                GCTWorks @dragoangel
                last edited by

                @dragoangel @Overlord What was the solution for non www to www?

                O 1 Reply Last reply Reply Quote 0
                • O
                  Overlord @GCTWorks
                  last edited by

                  @gctworks
                  I don't know anymore - I changed my whole setup but it's working fine.

                  In the access control lists I have

                  Name / Expression / CS / Not Value / Action
                  examplede / Host matches: / no / no / example.de
                  examplede / Host matches: / no / no / www.example.de

                  Action

                  Action / Parameters / Condition acl names
                  Use Backend / See below / examplede
                  backend: example.de

                  dragoangelD 1 Reply Last reply Reply Quote 0
                  • dragoangelD
                    dragoangel @Overlord
                    last edited by

                    @overlord just learn how to use Converters in HAproxy.

                    https://cbonte.github.io/haproxy-dconv/2.6/configuration.html#7.3.1, for example regsub.

                    http-request redirect code 301 location https://%[hdr(host),regsub(\"^www\.(.*)$\",\"\1\",i)]%[capture.req.uri] if { hdr_beg(host) -i www. }
                    

                    Latest stable pfSense on 2x XG-7100 and 1x Intel Xeon Server, running mutiWAN, he.net IPv6, pfBlockerNG-devel, HAProxy-devel, Syslog-ng, Zabbix-agent, OpenVPN, IPsec site-to-site, DNS-over-TLS...
                    Unifi AP-AC-LR with EAP RADIUS, US-24

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post
                    Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.