cancel
Showing results for 
Search instead for 
Did you mean: 
Login & Join the DevCentral Connects Group to watch the Recorded LiveStream (May 12) on Basic iControl Security - show notes included.

Multiple URIs redirect to single URL

iRule
Altostratus
Altostratus

Dear Community Experts,

 

I need multiple URIs to be redirected to single URL. Please share iRule that will accomplish this requirement.

Following three URIs need to be redirected to https://abcdef.com

1: "en/good/morning.aspx"

2: "en/good/evening.aspx"

3: "en/good/night.aspx"

 

I already have an iRule which successfully redirects one URI to single URL, which is shown below.

===============

when HTTP_REQUEST {

       if { [HTTP::uri] contains "en/good/morning.aspx"  } {

               HTTP::redirect "https://abcdef.com"

       }

}

==============

 

Instead of creating three iRules and assigning to virtual server I need one iRule to be created & assigned to virtual server.

 

Kind Regards

1 ACCEPTED SOLUTION

Samir
Nacreous
Nacreous

There are multiple ways to achieve it but would suggest you to add two more conditions in existing iRule.

when HTTP_REQUEST { if { ([HTTP::uri] contains "en/good/morning.aspx") || ([HTTP::uri] contains "en/good/evening.aspx") || ([HTTP::uri] contains "en/good/night.aspx") } { HTTP::redirect "https://abcdef.com" } }

Cheers...

View solution in original post

6 REPLIES 6

Samir
Nacreous
Nacreous

There are multiple ways to achieve it but would suggest you to add two more conditions in existing iRule.

when HTTP_REQUEST { if { ([HTTP::uri] contains "en/good/morning.aspx") || ([HTTP::uri] contains "en/good/evening.aspx") || ([HTTP::uri] contains "en/good/night.aspx") } { HTTP::redirect "https://abcdef.com" } }

Cheers...

Samir
Nacreous
Nacreous

There are multiple ways to achieve it but would suggest you to add two more conditions in existing iRule.

when HTTP_REQUEST { if { ([HTTP::uri] contains "en/good/morning.aspx") || ([HTTP::uri] contains "en/good/evening.aspx") || ([HTTP::uri] contains "en/good/night.aspx") } { HTTP::redirect "https://abcdef.com" } }

Cheers...

Thank you so much, it worked for me.

Just my two cents on this one: HTTP::redirect always sends an HTTP 302 (Temporary Redirect) status code. If you want to send a different status code (like HTTP 301 (Permanent Redirect)) should use HTTP::respond instead.

 

If you use a 302 is used instead of a 301, search engines might continue to index the old URL, and disregard the new one as a duplicate. 

Hi Daniel,

Thank you for your input.

If I follow your piece of advice then the iRule will be similar to bellow for any future iRule that I create?

 

  1. when HTTP_REQUEST {
  2. if { ([HTTP::uri] contains "en/good/morning.aspx") || ([HTTP::uri] contains "en/good/evening.aspx") || ([HTTP::uri] contains "en/good/night.aspx") } {
  3. HTTP::respond "https://abcdef.com"
  4. }
  5. }

 

Hi iRule,

 

please refer to this documentation: https://clouddocs.f5.com/api/irules/HTTP__respond.html

I'd probably add is like this:

HTTP::respond 301 -version auto noserver Location "https://abcdef.com"

KR

Daniel