irule redirect or rewrite

Hi

I need an irule to redirect from shortname: https://example to https://example.com/test

I used below irule , however shortname doesn’t work, but if I type fully qualified domain works just fine.

when HTTP_REQUEST { if { [string tolower [HTTP::host]] eq “/” } { HTTP::redirect “https://example.com/test” } }

Thx , all

so to be more specific if user type: https://example needs to be resolve to https://example.com/test in the address bar for the application to work.

Try this:

when HTTP_REQUEST { if { [string tolower [HTTP::host]] eq “example” } { HTTP::redirect “https://example.com/test” } }

I try that before not working, I am wondering if that needs to be done on the server site?

If the exact HTTP host they are trying to access is “example”, then the iRule will work. This assumes that you are terminating SSL on this virtual server and have an HTTP profile applied to the virtual server. Otherwise, you won’t have the visibility into the layer 7 HTTP data in order to do the comparison.

we have two hosts behind 443 VIP with SSL termination , requirement is if user type https://example must to resolved to FQN--> https://example.com/test. if I type https://example.com it will redirect fine to /test. is just short name ( example) doesn’t work. sorry for long explanation.

Is your DNS environment configured correctly to resolve ‘example’? It should either resolve to the same IP address as ‘example.com’, or CNAME to ‘example.com’.

I did tcpdump and I notice I am not seeing any packet to VIP, but if I use FQDN I see 3 way handshake. not sure DNS part, if I type shortname it resolves to same as FQDN

Perform these tests: nslookup example nslookup example.com Do these two resolve to the same IP address? If so, is this IP address your virtual server IP (or does it get translated via NAT to your virtual server IP)? Are you using any other controls (ASM, local traffic policies) that may not be allowing access to the virtual server by just the shortname?

if I do nslookup for “example” it display as below: address:192.168.1.10 aliases:example.com for example.com--> address:192.168.1.10 aliases:example.com 192.168.1.10 is F5 VIP for example.com and we don’t have any ASM or firewall to block. I am guessing something might miss configured on server site.

It sounds like DNS is resolving as intended. Are you certain your iRule is matching on ‘example’? Try putting a logging statement into the iRule and see if anything shows up in /var/log/ltm:

when HTTP_REQUEST { 
 if { [string tolower [HTTP::host]] eq "example" } { 
  log local0. "Matched example host, redirecting"
  HTTP::redirect "https://example.com/test" 
 } 
}

I put exact irule for logging, however I am not seeing it when accessing F5 VIP.

I did tecpdump , and I can only see it when I am using FQDN in my browser.nothing for short name. what does that mean? tcpdump -ni 0.0 host 192.168.110 and 172.16.1.10 192.168.1.10 is F5 vip and 172.16.1.10 is my pc. Thx

So then is ‘example’ getting CNAME’d to example.com? Could be that this is the case, and when the HTTP request arrives at your LTM, the host header specifies example.com and the iRule won’t match.

If you aren’t seeing traffic in the tcpdump when attempting to access https://example, then it seems like it isn’t making it to your virtual server. Your capture syntax should be: tcpdump -nni 0.0 host 192.168.1.10 and host 172.16.1.10

can you try wireshark on the laptop?