Forum Discussion

Hille_de_Graaf_'s avatar
Hille_de_Graaf_
Icon for Nimbostratus rankNimbostratus
Jan 31, 2008

http to https 301 redirect based on uri content

I am looking for a way to the following.

 

If I only enter the host, for example http://www.mysite.com, I want to send it with a HTTP-301 to https://www.mysite.com/home

 

If I enter http://www.mysite.com/whatever_uri/, I want to redirect it with a HTTP-301 to https://[HTTP::host][HTTP::uri]

 

 

I made the following iRule

 

 

when HTTP_REQUEST {

 

if {[HTTP::uri] == ""}{

 

HTTP::respond 301 Location "https://www.mysite.com/home"

 

}

 

else {

 

HTTP::respond 301 Location "https://www.mysite.com[HTTP::uri]"

 

}

 

}

 

 

 

However when I check it with live headers and enter http://www.mysite.com, I only see a 301 redirect to https://www.mysite.com and not to https://www.mysite.com/home, what I would aspect.

 

Has anyone an idea what is wrong?

 

 

Hille

2 Replies

  • Joe_Sabek_47241's avatar
    Joe_Sabek_47241
    Historic F5 Account
    Try using the following :-)

     

     

    when HTTP_REQUEST {

     

    if {[HTTP::uri] eq "/"}{

     

    HTTP::respond 301 Location "https://www.mysite.com/home"

     

    } else {

     

    HTTP::respond 301 Location "https://www.mysite.com[HTTP::uri]"

     

    }

     

    }