6

I would like to redirect the root of my website to a subsite by default. Like

http://www.domain.com/ ---> http://www.domain.com/subsite

I have tried this, but this matches all the URLs anyway:

acl is_root path_beg -i /
acl is_domain hdr(host) -i www.domain.com

redirect code 301 location http://www.domain.com/subsite if is_domain is_root

3 Answers3

16

nlu is almost there, but the is_root ACL is a little bit off.

Using path_beg will lead to any and all paths being matched, when really you only want to redirect requests with an empty path.

Try using acl is_root path -i / instead since it will only match when the path is ONLY /.

acl is_root path -i /
acl is_domain hdr(host) -i www.domain.com

redirect code 301 location http://www.domain.com/subsite if is_domain is_root
GregL
  • 9,370
  • 2
  • 25
  • 36
  • 1
    No problem, I find keeping track of all the derivatives of the sampling keywords to get a little bewildering myself, never mind keeping track of the keywords themselves. – GregL Jan 24 '15 at 19:28
  • In my use case, a match is also made for /?someurl. Meaning, it will follow the redirect, which is undesired. – Kevin C Jul 27 '20 at 14:18
  • It’s matching ‘/?someurl’ using the `path` sampler? – GregL Jul 27 '20 at 14:23
  • I only want the root path to be redirected, meaning domain.com/ So, I use the code you supplied. When configured, I also get redirected when using /another_url, which is undesired. – Kevin C Jul 27 '20 at 14:48
  • But are you using the `path`, or `path_beg` sampler? – GregL Jul 27 '20 at 19:40
  • i am using `path` – Kevin C Jul 28 '20 at 08:33
1

You can check, if it already starts with subsite and use the negated condition in the redirect:

acl is_subdomain    path_reg    ^/subsite/


acl is_root path_beg -i /
acl is_domain hdr(host) -i www.domain.com

redirect code 301 location http://www.domain.com/subsite if is_domain ! is_subdomain
nlu
  • 661
  • 5
  • 9
0

I had same issue, then i use acl below to resolved my issue.

    acl is_root path_beg -i /
    http-request set-path /subsite if is_root