Redirect www to non www
-
Hey,
My website is now accessible through two links:
www.website.com
website.comI 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 -
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):
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 -
@dragoangel it works, nice! thank you so much
-
@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!
-
@Overlord show your config, in pm if you want
-
@dragoangel @Overlord What was the solution for non www to www?
-
@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.deAction
Action / Parameters / Condition acl names
Use Backend / See below / examplede
backend: example.de -
@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. }