Forum Discussion
request needs to redirect from https://www.example.com to https://example.com/xyz
I needs to redirect the URL if a user enters https://www.example.com it should redirect to https://example.com/xyz , I have http to https irule applied on 80.
12 Replies
- nathe
Cirrocumulus
Mohammed,
Plenty of information/examples if you search for HTTP::redirect command in DevCentral.
Here's the documentation for HTTP::redirect to get you started.
N
- Mohammed_Akram
Altostratus
Thanks for the reply
all are working except if a user add www. its giving error . For the URL as am using wildcard cert
http://example.com or https://example.com or example.com or
http://www.example.com or https://www.example.com
should be redirect to https://example.com/xyz
- nathe
Cirrocumulus
a quick search of DC comes up with this: redirect www to https
- The_Y
Cirrus
Mohamed,
if you are looking for a static redirect then this should work
when HTTP_REQUEST { if {[string tolower [HTTP::host]] ends_with "example.com"} { HTTP::redirect "https://example.com/xyz" } }
- Hamish
Cirrocumulus
If www.example.com and example.com are the same VS, then this is the source of your looped redirect. You hit the same host again (example.com) and then redirect because your HOST ends with example.com...
You need to check the the URI is NOT /xyz already...
e.g
when HTTP_REQUEST { if { ([HTTP::uri] begins_with "/xyz") } { return } if {[string tolower [HTTP::host]] ends_with "example.com" } { HTTP::redirect "https://example.com/xyz" } }
Change begins_with to equals depending on what the rest of the content looks like...
- Mohammed_Akram
Altostratus
Error in Irule
- Mohammed_Akram
Altostratus
if a user enter https://www.example.com "HTTPS" then it is not redirecting . if a user hit http://www is redirecting but only https:// giving error.
- The_Y
Cirrus
If you are already doing an HTTP --> HTTPS redirect then this irule should only be added to your HTTPS Virtual server. Hope that helps
- Mohammed_Akram
Altostratus
It says redirected you too many times
- The_Y
Cirrus
Seems like you are having a redirect loop. Can you share your VS on config on port 80 and 443?
list ltm virtual <virtual_server>
- Mohammed_Akram
Altostratus
Below are the config on HTTP and HTTPS VIP
(HTTP_redirected)
list ltm virtual test-directory-redir
ltm virtual test-directory-redir {
creation-time 2019-06-17:13:17:31
destination X.X.X.X.:http
ip-protocol tcp
last-modified-time 2019-06-18:23:46:04
mask 255.255.255.255
profiles {
http { }
tcp { }
}
rules {
_sys_https_redirect
}
source 0.0.0.0/0
source-address-translation {
type automap
}
translate-address enabled
translate-port enabled
vs-index 43
}
___________________________________________________________________________________________________________
(HTTPS)
list ltm virtual test-directory
ltm virtual test-directory {
creation-time 2019-06-17:13:15:56
destination X.X.X.X:https
ip-protocol tcp
last-modified-time 2019-06-18:23:34:03
mask 255.255.255.255
persist {
dest_addr {
default yes
}
}
policies {
Gzip { }
}
pool Elaa_FII_Pool
profiles {
Elaa_Client_SSL {
context clientside
}
http { }
httpcompression { }
tcp { }
}
rules {
X-Forwarded-For
ends_with_www
}
source 0.0.0.0/0
source-address-translation {
type automap
}
translate-address enabled
translate-port enabled
vs-index 42
}
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com