Lets start with difference between URL and URI.

URL – http://afrozahmad.com/some/page.html

URI – /some/page.html

URL is the full way to identify any resource anywhere and can use different protocols like FTP, HTTP, SCP, etc.

URI is a resource on the current domain, so it needs less information to be found.

 

There are several methods of implementing URI redirection through IRULE, i have discussed three of them :-

1.  This method is widely used , although sometimes it doesn’t works , so try method 2 in that case.

when HTTP_REQUEST {
    switch -glob [string tolower [HTTP::host]] {         
        “www.afrozahmad.com” {
            switch -glob [HTTP::uri] {
                “/colorctrl” {
                    HTTP::respond 301 “Location” “http://www.afrozahmad.com/en/services/Pages/default.aspx”
                    # log local0. “***[IP::client_addr]:[TCP::client_port]:[HTTP::host]:[HTTP::uri]***”
                        }                
                    }
                }
            }
        }  

 

2. This method seems more logical , as it has lots if strings to play with .

when HTTP_REQUEST {
    switch -glob [string tolower [HTTP::host]] {         
        “afrozahmad.com” {
               if { [HTTP::uri] eq “/paper” } {     
                    HTTP::respond 301 “Location” “http://www.afrozahmad.com/paper”
                }
                if { [HTTP::uri] eq “/papers” } {     
                     HTTP::respond 301 “Location” “http://www.afrozahmad.com/papers”
                }
               else {
                    HTTP::respond 301 “Location” “http://www.afrozahmad.com”
                    }
                    #log local0. “***[IP::client_addr]:[TCP::client_port]:[HTTP::host]:[HTTP::uri]***”
        }
    }
}   

In above IRULE we have used “eq” OR “contains” for exact match, although we can use “starts_with”  to match words starting with particular letter.

3. In this method , instead of using  HTTP::respond 301 “Location”  we can use HTTP::redirect .

when HTTP_REQUEST {
  if { [HTTP::uri] contains “papers” } {
    HTTP::redirect https://[HTTP::host][HTTP::uri]
     }
}