Forum Discussion

7 Replies

  • when HTTP_REQUEST {
    
      if { [string tolower [HTTP::host]] eq "webpage.com") }{
        HTTP::respond 301 Location "http://www.webpage.com[HTTP::uri]" Connection Close
      }
    
    }
    
  • Hi,

    You can use an irule to detect if www is present and append it if not present :

    when HTTP_REQUEST {
        if { !([HTTP::host] contains "www.") } {
            HTTP::host "www.[HTTP::host]"
        }
    }
    
  • Something like this:

    when HTTP_REQUEST {
    
      if { [string tolower [HTTP::host]] eq "webpage.com" }{
        HTTP::respond 301 Location "http://www.webpage.com[HTTP::uri]" Connection Close
      }
    
    }
    
  • Ha, that was quick. Thanks for that. Just one more thing....

     

    I have some sub domains hitting that VS. IE. http://sub.webpage.com will the rule mean that www will be appended to the subdomain?

     

    Thanks

     

    Tom.

     

    • Hannes_Rapp's avatar
      Hannes_Rapp
      Icon for Nimbostratus rankNimbostratus
      No, because the conditional statement with 'eq' (stands for equals) will only trigger for an exact match
  • when HTTP_REQUEST {
        if { ! [HTTP::host] starts_with "www" } {
            HTTP::redirect http://www.[getfield [HTTP::host] ":" 1][HTTP::uri]
        }
    }
    

    Nice and all purpose...