Forum Discussion

Hien_Truong's avatar
Sep 11, 2020

irule redirect to different uri

Hi,

i need help to redirect:

https://www.abc.com/App/Topics/Topic.aspx?TopicId=* redirect to https://abc.com/redirect-legacy/abc-topics/Topic.aspx?TopicID=*

the below are two examples:

https://www.abc.com/App/Topics/Topic.aspx?TopicId=87

should go to

https://abc.com/redirect-tolegacy/abc-topics/Topic.aspx?TopicID=87

 

https://www.abc.gov/App/Topics/Topic.aspx?topicid=121

should go to

https://abc.com/redirect-tolegacy/abc-topics/Topic.aspx?TopicID=121

 

My below irule with string map is not working correctly.

when HTTP_REQUEST { 

if { ([string tolower [HTTP::host]] eq "www.abc.com") and ( [HTTP::uri] starts_with "/App/Topics/Topic.aspx?")} {

    HTTP::respond 301 noserver Location "https://www.abc.com[string map {/App/Topics/ /redirect-tolegacy/abc-topics/} [HTTP::uri]]"

  }

}

Any help i appreciate.

Thanks

3 Replies

  • Hi Hien Truong,

    Does redirected uri's hostname contains "www"?

    Can you try this?

    when HTTP_REQUEST { 
    	if { [HTTP::host] equals "www.abc.com" and [string tolower [HTTP::path]] equals "/app/topics/topic.aspx"} {
    		HTTP::respond 301 noserver Location "https://www.abc.com/redirect-tolegacy/abc-topics/Topic.aspx?[HTTP::query]"
    	}
    }
  • Thanks for your reply. The above irule is not working as expect since when we enter "TopicId=87" the output should be "TopicID=87". it mean when user type TopicId=* will ouput TopicID=*

    For example:

    https://www.abc.com/App/Topics/Topic.aspx?TopicId=87

    should go to

    https://www.abc.com/redirect-tolegacy/abc-topics/Topic.aspx?TopicID=87

     

    or

     

    https://www.abc.com/App/Topics/Topic.aspx?TopicId=1000

    should go to

    https://www.abc.com/redirect-tolegacy/abc-topics/Topic.aspx?TopicID=1000

    • Enes_Afsin_Al's avatar
      Enes_Afsin_Al
      Icon for MVP rankMVP
      when HTTP_REQUEST { 
      	if { [HTTP::host] equals "www.abc.com" and [string tolower [HTTP::path]] equals "/app/topics/topic.aspx"} {
      		HTTP::respond 301 noserver Location "https://www.abc.com/redirect-tolegacy/abc-topics/Topic.aspx?TopicID=[URI::query [HTTP::uri] TopicId]"
      	}
      }