Forum Discussion

5 Replies

  • Hi Ellen,

    You could potentially use a session cookie to track when someone had accessed a "root" URI like / or /index.htm. If someone makes a request to a non-root URI without the cookie, you could redirect them to a start page.

    This would potentially block access to your site though for any client who didn't support cookies. I'd be particularly concerned about search engine spiders.

    Here's an example iRule you could use for this. I'd try it on a test virtual server before considering it for production.

    
    when HTTP_REQUEST {
    
        Session cookie name used to track whether client has requested a root URI
       set name "my_session_cookie_name"
    
        URI to redirect clients to who haven't accessed a root URI before the current request
       set redirect_uri "http://www.example.com/index.htm"
    
        Track whether we need to insert a session cookie in the response
       set insert_cookie 0
    
        Check if request is to root document
       switch [HTTP::uri] {
          "/" -
          "/index.htm" {
    
      Insert a cookie in the response, if client doesn't have one already
             if { [HTTP::cookie $name] eq "" }{
    
                 Track that we need to set a session cookie in the response
                set insert_cookie 1
             }
          }
          default {
              Non-root page, so check for cookie
             if { [HTTP::cookie $name] eq "" }{
                HTTP::redirect $redirect_uri
             }
          }
       }
    }
    when HTTP_RESPONSE {
    
        Insert a session cookie if the client accessed a root URI and didn't have a cookie already
       if { $insert_cookie }{
          HTTP::cookie insert name $name value "1" path "/"
       }
    }
    

    Aaron

  • Dear Aaron:

     

    Thank you very much. Is inserting cookie the only way? There will be complaint from clients because blocking client access due to client not allow cookie insert.

     

  • Dear Aaron:

     

     

    Another question. will this iRule impact performance a lot?

     

     

    Ellen
  • I can't think of another way to implement this. I don't think the iRule is a good solution either though. It shouldn't add much load, but it will definitely affect accessibility of your site (no cookie support = no access).

     

     

    Are you able to provide more background on why you'd consider doing this? Are you concerned about web scraping or something similar?

     

     

    Aaron
  • For some special days, there are too many clients access our website. For these special days, we will design a simple home page(which contains just some link) to reduce network traffic and server loading. But some clients have bookmark some pages, then direct to these pages. So we need to let these clients that have bookmark some pages to enter website from the home page(first page).

     

    Anyway, thanks a lot.

     

     

    Ellen